System.Security.Cryptography

  • Post author:
  • Post category:其他


//System.Security.Cryptography 命名空间提供加密服务,包括安全的数据编码和解码,以及许多其他操作,例如散列法、随机数字生成和消息身份验证。

using System;

using System.Text;

using System.Globalization;

using System.Security.Cryptography;

class DES

{


// 创建Key

public string GenerateKey()

{


DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create();

return ASCIIEncoding.ASCII.GetString(desCrypto.Key);

}

// 加密字符串

public string EncryptString(string sInputString, string sKey)

{


byte [] data = Encoding.UTF8.GetBytes(sInputString);

DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);

DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

ICryptoTransform desencrypt = DES.CreateEncryptor();

byte [] result = desencrypt.TransformFinalBlock(data, 0, data.Length);



版权声明:本文为angela_sharmmy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。