encryption and decryption

G

Guest

I got the error of "Bad Data" when decrypting in PPC side, please help
thanks a lot!!!
the bytes are encrypted in desktop --->

byte[] writeBuffer = new byte[1024];
System.Text.ASCIIEncoding encode = new ASCIIEncoding ();
writeBuffer = encode.GetBytes(mServerMsg);
//encrypt the bytes to be sent
writeBuffer = Crypto.Encrypt (writeBuffer);
sock.send(writeBuffer);

private DES encryptAlg = new DESCryptoServiceProvider();
private static string pwd = "012345678901234567890";
private PasswordDeriveBytes pdb = new PasswordDeriveBytes(pwd,
new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
encryptAlg.Key = pdb.GetBytes (8);
encryptAlg.IV = pdb.GetBytes (8);

public byte[] Encrypt(byte[] inputByteArray)
{
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, encryptAlg.CreateEncryptor(),
CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return ms.ToArray ();
}
------------------------------------
PPC client decrypts -->

int rcount = sock.Receive(receiveByte,receiveByte.Length,0) ;
//decrypt the bytes received
receiveByte = cCryptoCls.Decrypt (receiveByte);
System.Text.ASCIIEncoding encode = new ASCIIEncoding ();
message = encode.GetString(receiveByte,0,receiveByte.Length ) ;
message = message.Substring(0,rcount);

private DES encryptAlg = new DESCryptoServiceProvider();
private static string pwd = "012345678901234567890";
private PasswordDeriveBytes pdb = new PasswordDeriveBytes(pwd,
new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
encryptAlg.Key = pdb.GetBytes (8);
encryptAlg.IV = pdb.GetBytes (8);
public byte[] Encrypt(byte[] input)
{
return encryptAlg.EncryptValue(input);
}
public byte[] Decrypt(byte[] input)
{
return encryptAlg.DecryptValue(input);
}
 
G

Guest

i can decrypt in the client side now
but the problem is that
server sends "apple"
but client decrypts like this " !!@#$ ple"

the byte length is the same in both side
what is the problem?

thanks a lot!!
 
F

Fernando Fanton [MSFT]

Hi Alan, could you please try to receive that data on a desktop application
and tell me what happen? Do you get the same message or is it able to
decrypt the information properly?

Thx
Fernando
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Thread-Topic: encryption and decryption
| thread-index: AcULkzr9ZH0yQ34LR/CoI4SveC94dw==
| X-WBNR-Posting-Host: 203.218.158.29
| From: "=?Utf-8?B?YWxhbg==?=" <[email protected]>
| Subject: encryption and decryption
| Date: Sat, 5 Feb 2005 06:59:02 -0800
| Lines: 55
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA0
3.phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.compactframework:70580
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| I got the error of "Bad Data" when decrypting in PPC side, please help
| thanks a lot!!!
| the bytes are encrypted in desktop --->
|
| byte[] writeBuffer = new byte[1024];
| System.Text.ASCIIEncoding encode = new ASCIIEncoding ();
| writeBuffer = encode.GetBytes(mServerMsg);
| //encrypt the bytes to be sent
| writeBuffer = Crypto.Encrypt (writeBuffer);
| sock.send(writeBuffer);
|
| private DES encryptAlg = new DESCryptoServiceProvider();
| private static string pwd = "012345678901234567890";
| private PasswordDeriveBytes pdb = new PasswordDeriveBytes(pwd,
| new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
| 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
| encryptAlg.Key = pdb.GetBytes (8);
| encryptAlg.IV = pdb.GetBytes (8);
|
| public byte[] Encrypt(byte[] inputByteArray)
| {
| MemoryStream ms = new MemoryStream();
| CryptoStream cs = new CryptoStream(ms, encryptAlg.CreateEncryptor(),
| CryptoStreamMode.Write);
| cs.Write(inputByteArray, 0, inputByteArray.Length);
| cs.FlushFinalBlock();
| return ms.ToArray ();
| }
| ------------------------------------
| PPC client decrypts -->
|
| int rcount = sock.Receive(receiveByte,receiveByte.Length,0) ;
| //decrypt the bytes received
| receiveByte = cCryptoCls.Decrypt (receiveByte);
| System.Text.ASCIIEncoding encode = new ASCIIEncoding ();
| message = encode.GetString(receiveByte,0,receiveByte.Length ) ;
| message = message.Substring(0,rcount);
|
| private DES encryptAlg = new DESCryptoServiceProvider();
| private static string pwd = "012345678901234567890";
| private PasswordDeriveBytes pdb = new PasswordDeriveBytes(pwd,
| new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
| 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
| encryptAlg.Key = pdb.GetBytes (8);
| encryptAlg.IV = pdb.GetBytes (8);
| public byte[] Encrypt(byte[] input)
| {
| return encryptAlg.EncryptValue(input);
| }
| public byte[] Decrypt(byte[] input)
| {
| return encryptAlg.DecryptValue(input);
| }
|
|
|
 

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