Guest User

Untitled

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. Dim aes_CryptoTransform As ICryptoTransform = AesCryptoServiceProvider.Create.CreateEncryptor(aesKeySet.Key, aesKeySet.IV)
  2. Dim textBytes() As Byte = System.Text.Encoding.ASCII.GetBytes(rtb_plaintext.Text)
  3.  
  4. Dim encrypted() As Byte
  5. using msEncrypt As New MemoryStream()
  6. using csEncrypt As New CryptoStream(textBytes, aes_CryptoTransform, CryptoStreamMode.write)
  7. using textStream as New StreamWriter(csEncrypt)
  8. swEncrypt.Write(plainText)
  9. End Using
  10. encrypted = msEncrypt.ToArray()
  11. csEncrypt.close()
  12. End Using
  13. End Using
  14.  
  15. dim textDirectoryPath as String = "C:encryptText.text"
  16. using textFilestream as new Filestream(textDirectoryPath, filemode.create)
  17. textFilestream.write(encrypted, 0, encrypted.length)
  18. textFilestream.close()
  19. end using
  20.  
  21. Dim aes_CryptoTransform As ICryptoTransform = AesCryptoServiceProvider.Create.CreateEncryptor(aesKeySet.Key, aesKeySet.IV)
  22.  
  23. Dim textBytesToDecrypt() As Byte = File.readAllBytes("C:encryptText.text")
  24. dim plainText as string = nothing
  25.  
  26. using msEncrypt As New MemoryStream(textBytesToDecrypt)
  27. using csEncrypt As New CryptoStream(textBytes, aes_CryptoTransform, CryptoStreamMode.read)
  28. using textStream as New StreamReader(csEncrypt)
  29. plainText = textStream.readToEnd()
  30. End Using
  31. csEncrypt.close()
  32. End Using
  33. End Using
Add Comment
Please, Sign In to add comment