如何加密/解密字符串?
跟进这个问题,我想知道什么是RSA关键是,我将如何在 C# 中创建和使用它。
Following up on this question, I would like to know what an RSA key is, and how I would go about creating and using one in C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自维基百科:
您是否查看过 RSACryptoServiceProvider< /a> 类? .NET 使大多数应用程序都可以轻松实现这一点。
From Wikipedia:
Have you looked at the RSACryptoServiceProvider class? .NET makes this easy for most applications.
有两种加密方式:对称加密和非对称加密。
对称加密使用发送者和接收者之间共享的单个密钥。
非对称加密,也称为公钥加密,使用两个密钥(密钥对),其中一个(私钥)保密,另一个(密钥对)保密,另一个(密钥对) >公钥)可供其他人使用。发送者使用接收者的公钥来加密数据,接收者使用他的私钥来解密数据。
RSA 是一种非对称/公钥加密方案。
AES 是一种对称加密方案。
混合方案将两者结合起来,以便使用对称加密对数据进行加密,但使用非对称加密对加密密钥本身进行加密、存储和交换。
因此,您需要弄清楚打算如何管理加密密钥。如果您正在设计一个只需要加密内容(例如,SSN 或密码)以将其保存到数据库,然后在需要使用它们时解密的系统,那么对称加密是合适的。如果您打算跨不同系统传输加密信息,那么非对称(或混合)加密是合适的。
There are two kinds of encryption: symmetric and asymmetric.
Symmetric crypto uses a single key that is shared between the sender and the receiver.
Asymmetric crypto, a.k.a. public-key cryptography, uses two keys (a key pair), one of which (the private key) is kept secret and the other (the public key) is made available to everyone else. The sender uses the public key of the receiver to encrypt data, and the receiver uses his private key to decrypt it.
RSA is an asymmetric/public-key crypto scheme.
AES is a symmetric crypto scheme.
Hybrid schemes combine both, so that the data is encrypted using symmetric encryption, but the encryption keys themselves are encrypted, stored, and exchanged using asymmetric encryption.
So you need to figure out how you intend to manage the encryption keys. If you're designing a system that only needs to encrypt things (e.g., SSNs or passwords) to save them to a database and then later decrypt them when it needs to use them, then symmetric crypto is appropriate. If you're intending to transmit encrypted info across different systems, then asymmetric (or hybrid) crypto is appropriate.