G
Guest
Modification to my earlier post, in case anyone thinks I am trying to code in
Java what we did in C#. We are trying to code in C# what we coded in Java,
so I do need C#, not Java, help. Anyway, we have existing code in Java
that encrypts a string using DES. However, when we encrypt in C# the string
is encrypted differently.
The code in C# is:
DES desAlg = new DESCryptoServiceProvider();
InitKey(epsKey);
desAlg.Key = dec_Key;
desAlg.IV = dec_Key;
byte[] bytIn = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncrypt);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ICryptoTransform encrypto = desAlg.CreateEncryptor();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
cs.Write(bytIn, 0, bytIn.Length);
cs.FlushFinalBlock();
ms.Close();
cs.Close();
byte[] resArray = ms.ToArray();
encryptedString = System.Convert.ToBase64String(resArray);
The code in Java is:
DESKeySpec desKeySpec = new DESKeySpec(epsKey.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ETYPE);
SecretKey key = keyFactory.generateSecret(desKeySpec);
ecipher = Cipher.getInstance(ETYPE);
ecipher.init(Cipher.ENCRYPT_MODE, key);
byte[] enc = ecipher.doFinal(str.getBytes("UTF8"));
encryptedString = new BASE64Encoder().encode(enc);
Any ideas?
Java what we did in C#. We are trying to code in C# what we coded in Java,
so I do need C#, not Java, help. Anyway, we have existing code in Java
that encrypts a string using DES. However, when we encrypt in C# the string
is encrypted differently.
The code in C# is:
DES desAlg = new DESCryptoServiceProvider();
InitKey(epsKey);
desAlg.Key = dec_Key;
desAlg.IV = dec_Key;
byte[] bytIn = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncrypt);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ICryptoTransform encrypto = desAlg.CreateEncryptor();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
cs.Write(bytIn, 0, bytIn.Length);
cs.FlushFinalBlock();
ms.Close();
cs.Close();
byte[] resArray = ms.ToArray();
encryptedString = System.Convert.ToBase64String(resArray);
The code in Java is:
DESKeySpec desKeySpec = new DESKeySpec(epsKey.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ETYPE);
SecretKey key = keyFactory.generateSecret(desKeySpec);
ecipher = Cipher.getInstance(ETYPE);
ecipher.init(Cipher.ENCRYPT_MODE, key);
byte[] enc = ecipher.doFinal(str.getBytes("UTF8"));
encryptedString = new BASE64Encoder().encode(enc);
Any ideas?