対称暗号化可逆DESENCRYPT

システムを使用しました。
System.Security.Cryptographyを使用しました。
System.Textのを使用しました。
System.Web.Securityを使用しました。

DESENCRYPT名前空間
{
/// <要約>
/// DES暗号化/復号化タイプ。
/// </要約>
パブリッククラスDESENCRYPT
{

#region ======== ========暗号化

/// <要約>
///加密
/// </要約>
/// <PARAM NAME = "テキスト"> </ param>の
/// <リターン> </リターン>
公共の静的な文字列の暗号化(文字列テキスト)
{
暗号化(テキスト、 "Mr_Cabbage")を返します。
}
/// <要約>
///加密数据
/// </要約>
/// <PARAM NAME = "テキスト"> </ PARAM>
/// <PARAM NAME = "のsKey"> </ PARAM>
/ // <戻る> </戻り>
パブリック静的文字列を暗号化(文字列テキスト文字列のsKey)
{
DESCryptoServiceProvider DES =新しいDESCryptoServiceProvider()。
バイト[] inputByteArray。
inputByteArray = Encoding.Default.GetBytes(テキスト)。
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(のsKey、 "MD5")サブストリング(0、8)。);
DES.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(のsKey、 "MD5")サブストリング(0、8)。);
System.IO.MemoryStream MS =新しいSystem.IO.MemoryStream()。
CryptoStream CS =新しいCryptoStream(MS、des.CreateEncryptor()、CryptoStreamMode.Write)。
cs.Write(inputByteArray、0、inputByteArray.Length)。
cs.FlushFinalBlock();
StringBuilderのRET =新しいStringBuilderの();
foreachの(ms.ToArrayのバイトB())
{
ret.AppendFormat( "{0:X2}"、B)。
}
)(ret.ToString返します。
}

#endregion

#region ======== ========解読

/// <要約>
///解密
/// </要約>
/// <PARAM NAME = "テキスト"> </ param>の
/// <リターン> </リターン>
公共の静的な文字列復号化(文字列テキスト)
{

(もし!string.IsNullOrEmpty(テキスト))
{
復号化(テキスト、 "Mr_Cabbage")を返します。
}

{
「」を返します。
}

}
/// <要約>
///解密数据
/// </要約>
/// <PARAM NAME = "テキスト"> </ PARAM>
/// <PARAM NAME = "のsKey"> </ PARAM>
/ // <戻る> </戻り>
パブリック静的文字列復号化(文字列テキスト文字列のsKey)
{
DESCryptoServiceProvider DES =新しいDESCryptoServiceProvider()。
int型のlen;
LEN = Text.Length / 2。
バイト[] inputByteArray =新しいバイト[LEN]。
int型のx、I。
(X = 0; X <LENあり; x ++)についての
{
I = Convert.ToInt32(Text.Substring(X * 2、2)、16)。
inputByteArray [X] =(バイト)I。
}
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication。
DES.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(のsKey、 "MD5")サブストリング(0、8)。);
System.IO.MemoryStream MS =新しいSystem.IO.MemoryStream()。
CryptoStream CS =新しいCryptoStream(MS、des.CreateDecryptor()、CryptoStreamMode.Write)。
cs.Write(inputByteArray、0、inputByteArray.Length)。
cs.FlushFinalBlock();
返すEncoding.Default.GetString(ms.ToArray());
}

#endregion

}
}

おすすめ

転載: www.cnblogs.com/vsnb/p/11223933.html