简体   繁体   English

编码中应使用哪种加密,它如何影响密钥和初始化向量?

[英]What encryption should be used in encoding and how does it affect key and initialisation vectors?

I'm getting my head around encryption and how encoding affects generation of the keys and initialization vectors. 我正在研究加密以及编码如何影响密钥和初始化向量的生成。

I'm working with a TripleDESCryptoServiceProvider which requires 24 byte key and 8 byte initialization vector using ASCII encoding. 我正在使用TripleDESCryptoServiceProvider ,它需要24个字节的密钥和8个使用ASCII编码的初始化向量。 If i decide to use a different encoding , how will this affect generation of the key and the initialization vector? 如果我决定使用其他编码,这将如何影响密钥和初始化向量的生成?

Which encoding should I be using instead UTF8/16/32? 我应该使用哪种编码代替UTF8 / 16/32?

Thank you 谢谢

The encryption parameters are completely unrelated to your choice of encoding. 加密参数与您选择的编码完全无关。 Encryption parameters are always defined in terms of bytes. 加密参数始终以字节为单位定义。 Encoding is concerned with translating characters to bytes and bytes back to characters. 编码与将字符转换为字节以及将字节转换回字符有关。 The only place they "collide" is using passwords to generate encryption keys. 他们“碰撞”的唯一场所是使用密码生成加密密钥。 You should use a class designed specifically to do this, like Rfc2898DeriveBytes . 您应该使用专门设计用于执行此操作的类,例如Rfc2898DeriveBytes

Most of the times I see ASCII encoding used the programmer would have been better served using UTF8 encoding. 大多数时候,我看到使用ASCII编码的程序员使用UTF8编码会更好。 UTF8 encoding encodes and decodes ASCII characters exactly the same way as ASCII encoding, but it also correctly and efficiently encodes all the rest of the Unicode. UTF8编码与ASCII编码完全一样地对ASCII字符进行编码和解码,但是它也可以正确,有效地编码所有其余的Unicode。 Use ASCII encoding if you need to generate an Exception when a non-ASCII character is encountered. 如果遇到非ASCII字符时需要生成异常,请使用ASCII编码。

I'm no expert, but, TripleDES is no longer considered secure enough. 我不是专家,但是,TripleDES不再被认为足够安全。 Microsoft's recommendation is to use AES 256 bit and above. 微软的建议是使用256位及以上的AES。 I don't think the text encoding affects the strength of the encryption, only the length of the "plain text" key and IV. 我认为文本编码不会影响加密的强度,而不会影响“纯文本”密钥和IV的长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM