且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Adobe AIR / Flash的高性能加密

更新时间:2023-12-03 18:50:40

至于性能,如果你可以流视频和放大器;音乐,即对其进行处理一块的时间,那么你只需要解密解密整个文件的一个块,而不是提前。这可能会不够好表现,无论算法。

Regarding performance, if you can stream the video & music, i.e. process them one block at a time, then you only need to decrypt one block ahead instead of decrypting the entire file. This will probably be good enough for performance no matter the algorithm.

有关***安全性的尝试AES-256,preferably在CTR模式(见的科林·珀西瓦尔的文章原理)。需要注意的是CTR模式转换的AES分组密码流加密相当于而不降低其安全性 - 这有一些有用的特性,如随机存取解密(对CBC这迫使你解密一切取决于你想要的数据)。

For the best security try AES-256, preferably in CTR mode (see Colin Percival's article for rationale). Note that CTR mode converts the AES block cipher to the equivalent of a stream cipher without reducing its security - this has some useful properties, like random-access decryption (vs. CBC which forces you to decrypt everything up to the data you want).

如果CPU负载过高,RC4是较弱的,但对于大多数应用已经足够了。一定要使用256位密钥。

If the CPU load is too high, RC4 is weaker but good enough for most uses. Be sure to use a 256-bit key.

最后,你的方式生成加密密钥时的很重要的:

Finally, the way you generate the encryption keys is very important:

如果您使用相同的基本密钥的所有文件进行加密,总是使用随机数(又名IV或初始化向量)加密时:

If you use the same base key to encrypt all the files, always use a nonce (a.k.a IV or "Initialization Vector") when encrypting:

  • 在一个随机数/ IV是一组随机字节被保留的中明确旁边的密文(通常prepended以密文)
  • 创建并使用不同的随机数/ IV每个加密文件
  • 在CTR模式的API包括一个方法来设置IV /随机数,使用该库还支持它
  • 如果您使用RC4:
    • 保存现时/ IV自己
    • 生成最终的加密密钥,使用HMAC-SHA256的基本密钥和随机数,就像提到这里
    • A nonce / IV is a group of random bytes that are kept in the clear next to your ciphertext (often prepended to the ciphertext)
    • Create and use a different nonce / IV for each encrypted file
    • CTR mode APIs include a way to set the IV / nonce, the library you use supports it
    • If you use RC4:
      • save the nonce / IV yourself
      • generate the final encryption key using HMAC-SHA256 with the base key and the nonce, like mentioned here

      如果用户输入密码,生成使用PBKDF2基加密密钥(再次,参见科林·珀西瓦尔的文章原理)。

      If the user enters a password, generate the base encryption key using PBKDF2 (again, see Colin Percival's article for rationale).

      既然你已经在图书馆的HMAC-SHA256执行可以很容易地实现PBKDF2-HMAC-SHA256自己,搜索网络左右的示例实现。

      Since you have an hmac-sha256 implementation in the library it's easy to implement PBKDF2-HMAC-SHA256 yourself, search the net or SO for sample implementations.