Converting encrypted data to String

M

MD

Hello,
i'm using the OpenNETCF.org framework so send encrypted data from a
Pocket PC to a server.
I neeed to send the encrypted data as a String and then decrypt it.
The code:

// encode data
Byte[] encodedBytes =
des.EncryptValue(System.Text.Encoding.ASCII.GetBytes(data));
String encodedBytesAsString =
System.Text.Encoding.ASCII.GetString(encodedBytes, 0,
encodedBytes.Length);

// send data

byte[] encodedBytes2 =
System.Text.Encoding.ASCII.GetBytes(encodedBytesAsString);
byte[] decodedBytes = des.EncryptValue(encodedBytes2);
String decodedBytesAsString =
System.Text.Encoding.ASCII.GetString(decodedBytes, 0,
decodedBytes.Length);


The decryption doesn't work.
Does anyone have an idea? Does it has to do something with the ASCII
conversion?

MD
 
D

Dieter

for crypt and decrypt strings in VB.Net (OpenNetCF)
I use this code: ( sorry for the formatting)


Public Function get_key(ByVal string_in As String) As String

If string_in <> "" Then

Dim DES As New TripleDESCryptoServiceProvider

DES.Key = (ASCIIEncoding.ASCII.GetBytes(Mid(deviceStr,
1,24)))
DES.IV = (ASCIIEncoding.ASCII.GetBytes(Mid(deviceStr, 1,
8)))
Dim UE As New UnicodeEncoding


Dim cs As Byte() =
DES.EncryptValue(UE.Unicode.GetBytes(string_in))

Return UE.Unicode.GetString(cs, 0, CInt(cs.Length))

End If



End Function



Public Function sent_key(ByVal string_in As String) As String

If string_in <> "" Then

Dim DES As New TripleDESCryptoServiceProvider

DES.Key = (ASCIIEncoding.ASCII.GetBytes(Mid(deviceStr, 1,
24)))

DES.IV = (ASCIIEncoding.ASCII.GetBytes(Mid(deviceStr, 1,
8)))

Dim UE As New UnicodeEncoding


' Dim cs As Byte() =
DES.EncryptValue(ASCIIEncoding.ASCII.GetBytes(string_in))
Dim cs As Byte() = (UE.Unicode.GetBytes(string_in))
Dim cs2 As Byte() = DES.DecryptValue(cs)

Return UE.Unicode.GetString(cs2, 0, CInt(cs2.Length))

End If


End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top