什麼是.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. 使用Jasypt加密和解密密碼
- 4. 加密和解密圖片.NET
- 5. Java RSA加密 - 解密.NET
- 6. 使用password_hash和SHA256加密和解密
- 7. AES加密和解密空加字節
- 8. php加密和解密數字字符串與密鑰
- 9. .Net |加密| ECC |如何使用.net框架執行ECC加密解密?
- 10. 使用字典進行加密/解密
- 11. 加密和解密
- 12. 加密和解密
- 13. 加密和解密
- 14. 加密和解密
- 15. 在.Net中加密/解密Sql Server 2005加密列NET
- 16. RAW RSA使用Crypto ++加密和解密
- 17. 使用Android和PHP加密/解密
- 18. 加密和解密使用RSAServiceProvider
- 19. RSA加密和解密使用X509certificate2
- 20. 加密和解密使用RSA OAEP
- 21. 使用mcrypt和sha-512加密解密?
- 22. PGP加密和解密使用
- 23. PGP使用Java加密和解密
- 24. 加密密鑰和加密字符串的解密
- 25. 加密,使用Rails解密
- 26. 使用Carrierwave加密/解密
- 27. 加密/解密使用EVP_ *
- 28. 使用AES加密/解密
- 29. 使用解密密鑰解密數據
- 30. 加密和解密一個字符串
感謝Marc,我只是想提到C#不會執行加密。 – 2009-07-29 13:53:00