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);
}
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);
}