使用C#和Java的RSA加密 [英] Using RSA encryption with C# and Java
问题描述
嘿伙计们,
我一直在努力尝试使用RSA加密Java中的数据,而b / b $ b解密C#中的数据。我已经能够使用
makecert创建X.509证书,并使用WSE在C#中成功访问它。从
certmgr作为CER导出后,我可以使用keytool在Java中使用它。
我的问题是,我根本无法解密Java加密消息C#。
如果我用C#加密和解密,一切都很好。我注意到的一件事是
,C#报告的模数与Java或openssl的模数不匹配
(匹配)。
有没有人在Java和C#之间成功使用过RSA?如果是这样,我会很感激
关于我可能出错的地方的任何提示。
谢谢,
布莱恩
" Bryan" <再***** @ thegroups.please>在消息中写道有没有人在Java和C#之间成功使用过RSA?如果是这样,我会
感谢任何关于我可能出错的提示。
这可能是一个字节序问题。尝试反转加密的字节,然后再将它们提供给RSACryptoServiceProvider [Array.Reverse可以帮助你
]。
此致,
Pieter Philippaerts
托管SSL / TLS: http://www.mentalis.org/go.php?sl
我试过反转字节,但我仍然当我尝试解密时,得到一个不好的
数据的CryptographicException。
我是用Java编码加密值的Base64编码并用C#解码它解密前
。当我打印出来时模数不匹配意味着
什么?或者.NET内部是否做了什么?
谢谢,
布莱恩
" Pieter Philippaerts" <裨**** @ nospam.mentalis.org>在消息中写道
news:ut ************** @ TK2MSFTNGP12.phx.gbl ..." Bryan" <再***** @ thegroups.please>在消息中写道有没有人在Java和C#之间成功使用过RSA?如果是这样,我会
欣赏关于我可能出错的任何提示。
它可以是一个端序问题。尝试反转加密的字节,然后将它们提供给RSACryptoServiceProvider [Array.Reverse可以帮助你
问候,
Pieter Philippaerts
托管SSL / TLS: http://www.mentalis.org/go.php ?sl
" blah" < BL ** @ blah.blah>在消息中写道我试图反转字节,但是当我尝试解密时,我仍然得到
坏数据的CryptographicException。
你能发布你正在使用的代码吗? [C#和Java]
问候,
Pieter Philippaerts
托管SSL / TLS: http://www.mentalis.org/go.php?sl
Hey guys,
I''ve been fighting with trying to use RSA to encrypt data in Java and
decrypt the data in C#. I''ve been able to create an X.509 certificate using
makecert and successfully access it in C# using WSE. After exporting from
certmgr as a CER, I can use it in Java using keytool.
My problem is, I simply cannot decrypt the Java encrypted messages in C#.
If I encrypt and decrypt in C#, everything is fine. One thing I noticed is
that the modulus reported by C# does not match that of Java or openssl
(which do match).
Has anyone successfully used RSA between Java and C#? If so, I''d appreciate
any tips on where I may be going wrong.
Thanks,
Bryan
"Bryan" <re*****@thegroups.please> wrote in messageHas anyone successfully used RSA between Java and C#? If so, I''d appreciate any tips on where I may be going wrong.
It can be an endian problem. Try reversing the encrypted bytes before
feeding them to the RSACryptoServiceProvider [Array.Reverse can help you
with that].
Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
I tried reversing the bytes, but I still get a CryptographicException of bad
data when I try to decrypt.
I am Base64 encoding the encrypted value in Java and decoding it in C#
before decrypting. Does the modulus not matching when I print it out mean
anything? Or does .NET do something to it internally?
Thanks,
Bryan
"Pieter Philippaerts" <Pi****@nospam.mentalis.org> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl..."Bryan" <re*****@thegroups.please> wrote in messageHas anyone successfully used RSA between Java and C#? If so, I''d
appreciateany tips on where I may be going wrong.
It can be an endian problem. Try reversing the encrypted bytes before
feeding them to the RSACryptoServiceProvider [Array.Reverse can help you
with that].
Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
"blah" <bl**@blah.blah> wrote in messageI tried reversing the bytes, but I still get a CryptographicException of bad data when I try to decrypt.
Can you post the code you''re using? [both C# and Java]
Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
这篇关于使用C#和Java的RSA加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!