Encryption | string using System;
Using System.Security;
Using System.Security.Cryptography;
Using System.Diagnostics;
Using System.Web;
Using System.Text;
Namespace Bigeagle.util
{
<summary>
An encryption class
<br>Author:Bigeagle@163.net</br>
<br>Date:2001/09/25</br>
<BR>HISTORY:2001/10/25 finished</br>
</summary>
<remarks>
Encapsulation of commonly used encryption algorithms
</remarks>
public Class cryptography
{
<summary>
MD5 encrypt the specified string
</summary>
<param name= "A_strvalue" > string to encrypt </param>
<returns> the encrypted string </returns>
public static string Encryptmd5string (String a_strvalue)
{
#if DEBUG
Debug.Assert (A_strvalue.trim ()!= "", "empty string", "empty string does not need encryption");
#endif//debug
<summary>
Determine if two encrypted strings are the same
</summary>
<param name= "A_STR1" ></param>
<param name= "A_STR2" ></param>
<returns> if the same return true </returns>
public static bool Issame (string a_str1, String a_str2)
{
Byte[] B1 = Stringtobytearray (A_STR1);
byte[] B2 = Stringtobytearray (A_STR2);
if (B1. Length!= B2. Length)
{
return false;
}
for (int i = 0; I < B1. Length; i + +)
{
if (B1[i]!= b2[i])
{
return false;
}
}
return true;
}
<summary>
Convert string to Byte tree Group
</summary>
<param name= "S" > string to be converted </param>
<returns> conversion of byte array </returns>
public static byte[] Stringtobytearray (String s)
{
/*
char[] CA = S.tochararray ();
byte[] ba = new BYTE[CA. Length];
for (int i=0; i<ba. Length; i++) Ba[i] = (Byte) ca[i];
Return ba;*/
return Encoding.UTF8.GetBytes (s);
}
<summary>
Convert byte array to string
</summary>
<param name= "a_arrbyte" >byte array </param>
<returns> string </returns>
public static string ByteArrayToString (byte[] a_arrbyte)
{
/*
char[] CA = new Char[a_arrbyte.length];
for (int i = 0; i < a_arrbyte.length i + +)
{
Result + = (char) a_arrbyte[i];
}*/
Return Encoding.UTF8.GetString (A_arrbyte);
}
<summary>
3DES encrypted string
</summary>
<param name= "A_strstring" > string to encrypt </param>
<param name= "A_strkey" > Key </param>
<returns> encoded string </returns> after encryption and base64
<remarks> static method, using default ASCII encoding </remarks>
public static string Encrypt3des (String a_strstring, String a_strkey)
{
TripleDESCryptoServiceProvider DES = new
TripleDESCryptoServiceProvider ();
MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.