![]() In this example, it is used to securely store private user data in a publicly accessible text file. The wrapper class can now be used to protect user assets. ' Convert the plaintext stream to a string. ' Create the decoder to write to the stream.ĭecStream.Write(encryptedBytes, 0, encryptedBytes.Length) ' Convert the encrypted text string to a byte array.ĭim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext) Return Convert.ToBase64String(ms.ToArray)Īdd a public method that decrypts a string. ' Convert the encrypted stream to a printable string. ' Use the crypto stream to write the byte array to the stream.ĮncStream.Write(plaintextBytes, 0, plaintextBytes.Length) ' Create the encoder to write to the stream. ' Convert the plaintext string to a byte array. TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ 8)Īdd a public method that encrypts a string. ![]() TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ 8) The key parameter controls the EncryptData and DecryptData methods. GetBytes(key)ĭim hash() As Byte = sha1.ComputeHash(keyBytes)Īdd a constructor to initialize the 3DES cryptographic service provider. Private Function TruncateHash(ĭim sha1 As New SHA1CryptoServiceProvider Private TripleDes As New TripleDESCryptoServiceProviderĪdd a private method that creates a byte array of a specified length from the hash of the specified key. In the Simple3Des class, add a private field to store the 3DES cryptographic service provider. Public NotInheritable Class Simple3DesĪdd an import of the cryptography namespace to the start of the file that contains the Simple3Des class. To create the encryption wrapperĬreate the Simple3Des class to encapsulate the encryption and decryption methods. For more information, see DES and Rijndael. The Rijndael (now referred to as Advanced Encryption Standard ) and Triple Data Encryption Standard (3DES) algorithms provide greater security than DES because they are more computationally intensive. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |