Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 27th, 2012  |  syntax: None  |  size: 1.23 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Encrypt in java and Decrypt in C# and reverse
  2. >     public string _secretPhrase = "123abc456";
  3. >     public string EncryptData(string plainText)
  4. >     {
  5. >         DES des = new DESCryptoServiceProvider();
  6. >         des.Mode = CipherMode.ECB;
  7. >         des.Padding = PaddingMode.PKCS7;
  8. >
  9. >         des.Key = Encoding.UTF8.GetBytes(_secretPhrase.Substring(0, 8));
  10. >         des.IV = Encoding.UTF8.GetBytes(_secretPhrase.Substring(0, 8));
  11. >
  12. >         byte[] bytes = Encoding.UTF8.GetBytes(plainText);
  13. >         byte[] resultBytes = des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  14. >
  15. >         return Convert.ToBase64String(resultBytes);
  16. >     }
  17. >
  18. >     public string DecryptData(string encryptedText)
  19. >     {
  20. >         DES des = new DESCryptoServiceProvider();
  21. >         des.Mode = CipherMode.ECB;
  22. >         des.Padding = PaddingMode.PKCS7;
  23. >         des.Key = Encoding.UTF8.GetBytes(_secretPhrase.Substring(0, 8));
  24. >         des.IV = System.Text.Encoding.UTF8.GetBytes(_secretPhrase.Substring(0, 8));
  25. >
  26. >         byte[] bytes = Convert.FromBase64String(encryptedText);
  27. >         byte[] resultBytes = des.CreateDecryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  28. >
  29. >         return Encoding.UTF8.GetString(resultBytes);
  30. >     }