dreamone5156 2011-11-20 06:06
浏览 40

我想实现从BlackBerry到PHP的共享秘密加密

The https handshake is unbearably slow in a BlackBerry app, so I'm going to try to use their native encryption functions to send private data to my server via http. I can send a unique shared secret key to the device using a one-time https transfer so I think this scheme is relatively secure unless someone gets access to the device, but I'm not concerned about that.

I've found the encrypt() function in the following BlackBerry article: http://supportforums.blackberry.com/t5/Java-Development/Use-Basic-Encryption/ta-p/445092

I've been tinkering with it and it seems to produce encrypted output.

The question is, how do I decrypt this on the server side in PHP using mcrypt_decrypt()?

I'm by no means an encryption expert and all the options are making my head spin. Key size, block size, block cipher mode, IV, etc.

I read in the comments here How to write AES/CBC/PKCS5Padding encryption and decryption with Initialization Vector Parameter for BlackBerry that maybe I should use a CBCEncryptorEngine on the BlackBerry side. The encrypt() example doesn't specify a block cipher mode, so adding this seems to make sense since mcrypt_decrypt() seems to want one.

Then does the IV have to be sent along with the encrypted data? it seems to be required Obviously I'm out of my element here.

I'm tinkering with this code in PHP:

mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $sSecretKey, $sEncrypted, MCRYPT_MODE_ECB);

But honestly I have no clue what constants to use and whether I need the IV. Naturally, it's giving me garbage out.

Can someone help me put these pieces together?

  • 写回答

1条回答 默认 最新

  • douzhi3667 2011-11-21 00:46
    关注

    So that there's an official answer here, it turns out the PHP code I listed in the question actually works perfectly to decrypt the output from the encrypt() function in the BlackBerry knowledgebase article.

    I'll look into adding CBC for more security but it might not be a requirement in my case since the data I'm sending is very variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计