哪位大神能把C#这段代码用java代码写出来 感激不尽 50
privatevoidbutton1_Click(objectsender,EventArgse){try{byte[]buffer;RijndaelManagedman...
private void button1_Click(object sender, EventArgs e)
{
try
{
byte[] buffer;
RijndaelManaged managed = new RijndaelManaged();
managed.Key = Encoding.ASCII.GetBytes("70FF6ACA429742BA");
managed.IV = Encoding.ASCII.GetBytes("A1F319B2-F064450");
ICryptoTransform transform = managed.CreateDecryptor();
if (this.checkBox1.Checked)
{
buffer = Convert.FromBase64String(this.textBox1.Text.Replace("~", "/").Replace("`", "+"));
}
else
{
buffer = Convert.FromBase64String(this.textBox1.Text.Replace("♂", "/").Replace("♀", "+").Replace("□", "="));
}
MemoryStream stream = new MemoryStream(buffer);
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read);
StreamReader reader = new StreamReader(stream2);
this.textBox2.Text = reader.ReadToEnd().TrimEnd(new char[0]);
stream.Close();
reader.Close();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
} 展开
{
try
{
byte[] buffer;
RijndaelManaged managed = new RijndaelManaged();
managed.Key = Encoding.ASCII.GetBytes("70FF6ACA429742BA");
managed.IV = Encoding.ASCII.GetBytes("A1F319B2-F064450");
ICryptoTransform transform = managed.CreateDecryptor();
if (this.checkBox1.Checked)
{
buffer = Convert.FromBase64String(this.textBox1.Text.Replace("~", "/").Replace("`", "+"));
}
else
{
buffer = Convert.FromBase64String(this.textBox1.Text.Replace("♂", "/").Replace("♀", "+").Replace("□", "="));
}
MemoryStream stream = new MemoryStream(buffer);
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read);
StreamReader reader = new StreamReader(stream2);
this.textBox2.Text = reader.ReadToEnd().TrimEnd(new char[0]);
stream.Close();
reader.Close();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
} 展开
2014-07-03
展开全部
RijndaelManaged managed = new RijndaelManaged();
和
CryptoStream
这两个改不了。 后面的再怎么转换,没意义了。
下面讲讲关键的转换
1、
Encoding.ASCII.GetBytes("70FF6ACA429742BA");
--->
"70FF6ACA429742BA".getBytes();
2、
Base64,建议使用apacher commons-code里面的base64类。
3、
MemoryStream,可以使用java.io.ByteArrayOutputStream
和
CryptoStream
这两个改不了。 后面的再怎么转换,没意义了。
下面讲讲关键的转换
1、
Encoding.ASCII.GetBytes("70FF6ACA429742BA");
--->
"70FF6ACA429742BA".getBytes();
2、
Base64,建议使用apacher commons-code里面的base64类。
3、
MemoryStream,可以使用java.io.ByteArrayOutputStream
追问
RijndaelManaged我的关键就是这个 JAVA也有AES算法实现的例子 但是根本跟这个加密后的密文不一样啊·~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询