Public ClassCLS_JM'Use 'Dim Jm as New cls_jm (2) 'Dim strtmp as String 'Jm.jiemi (strtmp) 'Jm.jiami (strtmp) PrivateTripleDes as NewSystem.Security.Cryptography.TripleDESCryptoServiceProviderPrivate FunctionTruncatehash (ByValKey as String,ByValLength as Integer) as Byte() DimSha1 as NewSystem.Security.Cryptography.SHA1CryptoServiceProvider'Hash the key. DimKeybytes () as Byte=System.Text.Encoding.Unicode.GetBytes (Key)DimHash () as Byte= Sha1.computehash (keybytes)'Truncate or pad the hash. ReDim PreserveHash (Length-1) ReturnHashEnd Function Sub New(ByValKey as String)'Initialize the crypto provider. Tripledes.key = Truncatehash (Key, tripledes.keysize \8) Tripledes.iv= Truncatehash ("", Tripledes.blocksize \8) End Sub Public FunctionJiami (ByValPlainText as String) as String 'Convert the plaintext string to a byte array. DimPlaintextbytes () as Byte= System.Text.Encoding.Unicode.GetBytes (plaintext)'Create the stream. DimMs as NewSystem.IO.MemoryStream'Create the encoder to write to the stream. DimEncstream as NewSystem.Security.Cryptography.CryptoStream (MS, Tripledes.createencryptor (), System.Security.Cryptography.CryptoStreamMode.Write)'Use the crypto stream to write the byte array to the stream.Encstream.write (Plaintextbytes,0, Plaintextbytes.length) encstream.flushfinalblock ()'Convert the encrypted stream to a printable string. Returnconvert.tobase64string (Ms. ToArray)End Function Public FunctionJiemi (ByValEncryptedtext as String) as String 'Convert the encrypted text string to a byte array. DimEncryptedbytes () as Byte= Convert.frombase64string (Encryptedtext)'Create the stream. DimMs as NewSystem.IO.MemoryStream'Create the decoder to write to the stream. DimDecstream as NewSystem.Security.Cryptography.CryptoStream (MS, Tripledes.createdecryptor (), System.Security.Cryptography.CryptoStreamMode.Write)'Use the crypto stream to write the byte array to the stream.Decstream.write (Encryptedbytes,0, Encryptedbytes.length) decstream.flushfinalblock ()'Convert the plaintext stream to a string. ReturnSystem.Text.Encoding.Unicode.GetString (Ms. ToArray)End FunctionEnd Class
VB.net string Encryption Class