我有这个问题,而且很多天都在挣扎 下面的代码我需要在公共.cer文件中加密c#
string encrytedText; SKey1 = aem.Key; string CERTFPATH = ConfigurationManager.AppSettings [ UIDAIPublicCertificate]的ToString(); X509Certificate2 uidCert = new X509Certificate2(CERTFPATH, public,X509KeyStorageFlags.DefaultKeySet); RSACryptoServiceProvider RSA =(RSACryptoServiceProvider)uidCert.PublicKey.Key; { RSAParameters RSAKeyInfo = RSA.ExportParameters( false ); encrytedText = Convert.ToBase64String(RSA.Encrypt(SKey1, false )); } return encrytedText;i将上面生成的加密文本传递给第三方创建的java api,它没有在java api上正确解密结束 有人可以帮助我们吗? 我尝试了什么: 来自搜索,我得到了参考,因为你可以使用充气城堡,但我有代码,我可以使用有2058密钥长度的公共证书来加密它
解决方案你需要做的第一件事就是找出问题所在。 所以用C#加密它,然后写代码解密它在C#中。 如果结果与输入相同,请继续进行下一次检查:它是否正在转移?检查Java代码将根据C#的输出解密的数据。它是一样的吗?如果是这样,接下来检查一下:Java做了什么?编写Java代码来加密原始材料。编写代码来解密它。输出是否与输入相同?如果是,则将Java的加密输出与C#加密的输出进行比较。它们是一样的吗? 在某些时候,你会发现一个不同之处。然后你可以专注于为什么。但是直到你知道问题出在哪里,你只是在黑暗中吹口哨。
我使用 RijndaelManaged managed = new RijndaelManaged();
加密类然后我的这个问题已经解决了, 如果有人需要示例代码,请发邮件给我个人vipul.ghadge@gmail
hi, I have this problem , and being struggling lots of days Below code i have for encryption in c# from public .cer file
string encrytedText; SKey1 = aem.Key; string CERTFPATH = ConfigurationManager.AppSettings["UIDAIPublicCertificate"].ToString(); X509Certificate2 uidCert = new X509Certificate2(CERTFPATH, "public", X509KeyStorageFlags.DefaultKeySet); RSACryptoServiceProvider RSA = (RSACryptoServiceProvider)uidCert.PublicKey.Key; { RSAParameters RSAKeyInfo = RSA.ExportParameters(false); encrytedText = Convert.ToBase64String(RSA.Encrypt(SKey1, false)); } return encrytedText;i pass above generated encrypted text to java api create by third party , it doesn't getting properly decrypted at java api end could anybody help us ? What I have tried: from search , i got references as you can use bouncy Castle , but i havnt got code where i can use public certificate which has 2058 key length to encrypt it
解决方案 The first thing you need to do is find out where the problem is. So encrypt it in C#, then write code to decrypt it in C#. If the result is the same as the input, move on to the next check: it is getting transferred ok? Check the data the Java code is going to decrypt against the output of the C#. Is it identical? If so, next check: what does the Java do? Write Java code to encrypt the original material. Write code to decrypt it. Is the output the same as the input? If it is, compare the encrypted output from the Java with the output from the C# encryption. Are they the same? At some point, you'll find a difference. Then you can concentrate on why. But until you know where the problem starts, you are just whistling in the dark.I have use RijndaelManaged managed = new RijndaelManaged();class for encryption then my this issue has resolved , if any one need sample code , mail me i will provide in personal vipul.ghadge@gmail
更多推荐
加密程序是用C#编写的,但解密是用java编写的
发布评论