VB.net string Encryption Class

Source: Internet
Author: User
Tags sha1

 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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.