G
Guest
Hi,
Using the system.security.cryptography i have an encrypted byte() array
which Im trying to decrypt but it doesnt appear to work. It seams when I pass
the memory stream to the crypto stream nothing happens. Code below...
Any ideas TIA
Stu
Public Function decryptByteStream() As Byte()
Dim bytKey(), arStream(), arDecStream() As Byte
Dim encrypto As ICryptoTransform
Dim cs As CryptoStream
Dim objMemStream As MemoryStream
Dim objBinReader As BinaryReader
Try
bytKey = GetLegalKey(_cKey)
'set the private key
_CryptoService.Key = bytKey
_CryptoService.IV = bytIV
'create a Decryptor from the Provider Service instance
encrypto = _CryptoService.CreateDecryptor()
objMemStream = New MemoryStream(_arEncByteStream)
'create Crypto Stream that transforms a stream using the
decryption
cs = New CryptoStream(objMemStream, encrypto,
CryptoStreamMode.Read)
cs.FlushFinalBlock()
objBinReader = New BinaryReader(cs)
arDecStream = objBinReader.ReadBytes(cs.Length)
Catch err As Exception
_cError = err.Message
Finally
cs.Close()
End Try
Return arDecStream
End Function
Using the system.security.cryptography i have an encrypted byte() array
which Im trying to decrypt but it doesnt appear to work. It seams when I pass
the memory stream to the crypto stream nothing happens. Code below...
Any ideas TIA
Stu
Public Function decryptByteStream() As Byte()
Dim bytKey(), arStream(), arDecStream() As Byte
Dim encrypto As ICryptoTransform
Dim cs As CryptoStream
Dim objMemStream As MemoryStream
Dim objBinReader As BinaryReader
Try
bytKey = GetLegalKey(_cKey)
'set the private key
_CryptoService.Key = bytKey
_CryptoService.IV = bytIV
'create a Decryptor from the Provider Service instance
encrypto = _CryptoService.CreateDecryptor()
objMemStream = New MemoryStream(_arEncByteStream)
'create Crypto Stream that transforms a stream using the
decryption
cs = New CryptoStream(objMemStream, encrypto,
CryptoStreamMode.Read)
cs.FlushFinalBlock()
objBinReader = New BinaryReader(cs)
arDecStream = objBinReader.ReadBytes(cs.Length)
Catch err As Exception
_cError = err.Message
Finally
cs.Close()
End Try
Return arDecStream
End Function