AES加密在C#(帮助)和解密在Java中(完成) [英] AES Encrypt in C# (Help) and Decrypt in Java (Done)
问题描述
我们有一个需要到Java应用程序通过一些数据.NET应用程序。我们想给它一些简单的加密,M.C.霍金不会被盗号的,但它需要不是纯文本。
We have a .NET application that needs to pass some data over to a Java app. We are wanting to give it some simple encryption, M.C. Hawking wont be hacking in but it needs to not be plain text.
我发现了一些伟大的Java代码,让我加密/使用AES解密。我所希望找到的是本作的C#,这将让我加密的字符串,将解密的跟我的Java程序的匹配peice的。
I found some great Java code that lets me encrypt/decrypt using AES. What I am hoping to find is the matching peice of this for C# that will let me Encrypt a string that will be decryptable with my Java routine.
下面是我的java类
class SimpleProtector
{
private final String ALGORITHM = "AES";
private final byte[] keyValue = new byte[] { 'T', 'h', 'i', 's', 'I', 's', 'A', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y' };
public String encrypt(String valueToEnc) throws Exception
{
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encValue = c.doFinal(valueToEnc.getBytes());
String encryptedValue = new BASE64Encoder().encode(encValue);
return encryptedValue;
}
public String decrypt(String encryptedValue) throws Exception
{
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.DECRYPT_MODE, key);
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedValue);
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}
private Key generateKey() throws Exception
{
Key key = new SecretKeySpec(keyValue, ALGORITHM);
return key;
}
}
感谢您的任何提示!
Thanks for any tips!
推荐答案
请参阅这个问题的答案:的 http://stackoverflow.com/questions/273452/c-implementations-of-aes-encryption
See answers to this question: http://stackoverflow.com/questions/273452/c-implementations-of-aes-encryption
这篇关于AES加密在C#(帮助)和解密在Java中(完成)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!