Hi everyone,
Can you help me please? I am having a problem with the
encryption/decryption of words with the Irish fada in them. The Irish
fada is like this: αινσϊ/ΑΙΝΣΪ. It's kind of like the French
grave...
Anyway when I run encryption on a plaintext word like:
RΝΣS NΑ RΪN
I get the following:
UKFzsStlitpd/QhEjqm0eQA=
However, when I decrypt it I get the following:
RΓΓ"S NΓ RΓN
As you can see it does not match the original plaintext. This is weird
- no? I'm confused - I was expecting the same original plaintext.
Can anyone help me please? I have the encryption/decryprion code
below. I pulled it off the net. I would greatly appreciate any
suggestions/commends/omprovements. I want to get the original plaintext
when I decrypt - that's the naturte of the problem... please help me!
******* ENCRYPTION STUFF *******
Public Shared Function EncryptString(ByVal AString As String) As
String
If AString = String.Empty Then
Return AString
Else
Dim encryptedData() As Byte
Dim dataStream As MemoryStream
Dim encryptor As ICryptoTransform
encryptor = mProvider.CreateEncryptor()
Try
dataStream = New MemoryStream
Dim encryptedStream As CryptoStream
Try
'Create the encrypted stream
encryptedStream = New CryptoStream(dataStream,
encryptor, CryptoStreamMode.Write)
Dim theWriter As StreamWriter
Try
'Write the string to memory via the encryption
algorithm
theWriter = New StreamWriter(encryptedStream)
'Write the string to the memory stream
theWriter.Write(AString)
'End the writing
theWriter.Flush()
encryptedStream.FlushFinalBlock()
'Position back at start
dataStream.Position = 0
'Create area for data
ReDim encryptedData(CInt(dataStream.Length))
'Read data from memory
dataStream.Read(encryptedData, 0,
CInt(dataStream.Length))
'Convert to String
Return Convert.ToBase64String(encryptedData, 0,
encryptedData.Length)
Finally
theWriter.Close()
End Try
Finally
encryptedStream.Close()
End Try
Finally
dataStream.Close()
End Try
End If
End Function
******* DECRYPTION STUFF *******
Public Shared Function DecryptString(ByVal AString As String) As
String
If AString = String.Empty Then
Return AString
Else
Dim encryptedData() As Byte
Dim dataStream As MemoryStream
Dim encryptedStream As CryptoStream
Dim strLen As Integer
'Get the byte data
encryptedData = Convert.FromBase64String(AString)
Try
dataStream = New MemoryStream
Try
'Create decryptor and stream
Dim decryptor As ICryptoTransform
decryptor = mProvider.CreateDecryptor()
encryptedStream = New CryptoStream(dataStream,
decryptor, CryptoStreamMode.Write)
'Write the decrypted data to the memory stream
encryptedStream.Write(encryptedData, 0,
encryptedData.Length - 1)
encryptedStream.FlushFinalBlock()
'Position back at start
dataStream.Position = 0
'Determine length of decrypted string
strLen = CInt(dataStream.Length)
'Create area for data
ReDim encryptedData(strLen - 1)
'Read decrypted data to byte()
dataStream.Read(encryptedData, 0, strLen)
'Construct string from byte()
Dim retStr As String
Dim i As Integer
For i = 0 To strLen - 1
retStr += Chr(encryptedData(i))
Next
'Return result
Return retStr
Finally
encryptedStream.Close()
End Try
Finally
dataStream.Close()
End Try
End If
End Function