什麼是.NET可用的加密技術(使用C#)。我有一個數字值,我想要加密到一個字符串表示。哪一個解密支持?使用.NET加密和解密數字
4
A
回答
5
加密(由.NET框架/ BCL提供,而不是C#語言)通常對字節起作用。但這很好;數字很容易表示爲字節,輸出字節可以通過Convert.ToBase64String
以字符串的形式寫入。
因此, 「所有的人,間接」 ......
見System.Security.Cryptography
on MSDN
(再解密:一個加密進行解密;一個哈希不能(希望);所以只要你不看的散列函數,你應該罰款)
5
System.Security.Cryptography -
System.Security.Cryptography命名空間提供加密服務,包括數據的安全編碼和解碼以及許多其他操作,如散列,隨機數生成和消息認證。
Example Walkthrough演示如何加密和解密內容。
1
我首先查看Cryptography命名空間。你可以實現你自己的解密/加密字符串函數。 Here就是一個很好的例子。
3
不管你做什麼,都不要滾動你自己的加密算法。命名空間將包含您需要的所有內容:
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String secret = "Zomg!";
byte[] secretBytes = ASCIIEncoding.ASCII.GetBytes(secret);
// One-way hashing
String hashedSecret =
BitConverter.ToString(
SHA512Managed.Create().ComputeHash(secretBytes)
);
// Encryption using symmetric key
Rijndael rijndael = RijndaelManaged.Create();
ICryptoTransform rijEncryptor = rijndael.CreateEncryptor();
ICryptoTransform rijDecryptor = rijndael.CreateDecryptor();
byte[] rijndaelEncrypted = rijEncryptor.TransformFinalBlock(secretBytes, 0, secretBytes.Length);
String rijndaelDecrypted =
ASCIIEncoding.ASCII.GetString(
rijDecryptor.TransformFinalBlock(rijndaelEncrypted, 0, rijndaelEncrypted.Length)
);
// Encryption using asymmetric key
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
string rsaParams = rsa.ToXmlString(true); // you can store the public key in a config file
// which allows you to recreate the file later
byte[] rsaEncrypted = rsa.Encrypt(secretBytes, false);
String decrypted =
ASCIIEncoding.ASCII.GetString(
rsa.Decrypt(rsaEncrypted, false)
);
// Signing data using the rsaEncryptor we just created
byte[] signedData = rsa.SignData(secretBytes, new SHA1CryptoServiceProvider());
bool verifiedData = rsa.VerifyData(secretBytes, new SHA1CryptoServiceProvider(), signedData);
}
}
}
相關問題
- 1. RSA加密用Java/.NET和解密.NET
- 2. 用密鑰加密和解密數據
- 3. 加密和解密圖片.NET
- 4. 使用Jasypt加密和解密密碼
- 5. 使用php加密和解密密碼
- 6. Java RSA加密 - 解密.NET
- 7. RSA .NET加密Java解密
- 8. 加密和解密的字節數組
- 9. AES在.NET中加密並使用Node.js加密解密?
- 10. Swift - 使用用戶密碼加密和解密字符串
- 11. 使用iOS和PHP加密和解密
- 12. 使用password_hash和SHA256加密和解密
- 13. 在Python中解密使用.NET加密的字符串
- 14. .Net |加密| ECC |如何使用.net框架執行ECC加密解密?
- 15. AES加密和解密空加字節
- 16. php加密和解密數字字符串與密鑰
- 17. 使用字典進行加密/解密
- 18. 在.Net中加密/解密Sql Server 2005加密列NET
- 19. 加密和解密
- 20. 加密和解密
- 21. 加密和解密
- 22. 加密和解密
- 23. 加密和解密密碼
- 24. 使用C++進行加密和解密
- 25. 加密和解密使用Base64算法
- 26. 使用mcrypt和sha-512加密解密?
- 27. RAW RSA使用Crypto ++加密和解密
- 28. 加密和解密使用PyCrypto AES 256
- 29. RSA加密和解密使用X509certificate2
- 30. 使用PHP加密和解密
感謝Marc,我只是想提到C#不會執行加密。 – 2009-07-29 13:53:00