以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- PEM格式密钥怎么处理啊 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=194643) |
-- 作者:aidimeng -- 发布时间:2025/1/1 13:15:00 -- PEM格式密钥怎么处理啊 Dim rsa = New System.Security.Cryptography.RSACryptoServiceProvider() Dim ByteConverter As New UnicodeEncoding() \'Dim dataToEncrypt As Byte() = ByteConverter.GetBytes("ww我wData to Encrypt") \'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2KbR4DybAGoFvZleBqdHtnX03Bf2CvzsdCZf8/t5mNsISlKdkRVeqc7JimvHny7sICCMmmWZYu33ZzJkDXSKB8JDM2hugwB3Von8aWiMYxKjq43Hn0vfv7M+70WjX0TNGoyMFLKSN9rsqMtIAuD+Ipv6Aovlw+1PjGMPZ2XtUbB010/JEP7d1NjyKxKhFryKzBOc4FhNfis6EJIpsFnA1LKIvg/Mw0BY/f9u6lafCPR+OO4Ula4PShV1nD3TfNYlWNCocZtxVlVfqR78c0Tpe2+jkG8BEtylzff2olEf0z+YwxqyOdHxutMlEnoYa16kkqpc+IRdeaGhcKSwpKvk4QIDAQAB Dim dataToEncrypt As String = "784e9291-e51f-4b12-900e-3736b0d401f3" Dim pck As String = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2KbR4DybAGoFvZleBqdHtnX03Bf2CvzsdCZf8/t5mNsISlKdkRVeqc7JimvHny7sICCMmmWZYu33ZzJkDXSKB8JDM2hugwB3Von8aWiMYxKjq43Hn0vfv7M+70WjX0TNGoyMFLKSN9rsqMtIAuD+Ipv6Aovlw+1PjGMPZ2XtUbB010/JEP7d1NjyKxKhFryKzBOc4FhNfis6EJIpsFnA1LKIvg/Mw0BY/f9u6lafCPR+OO4Ula4PShV1nD3TfNYlWNCocZtxVlVfqR78c0Tpe2+jkG8BEtylzff2olEf0z+YwxqyOdHxutMlEnoYa16kkqpc+IRdeaGhcKSwpKvk4QIDAQAB" Dim encryptedData() As Byte Dim decryptedData() As Byte Dim gs As String = "<RSAKeyValue><Modulus>" & pck & "</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"\'rsa.ToXmlString(False) \'生成 公匙 Output.Show(gs) Dim ss As String = rsa.ToXmlString(True) \'\'生成 私匙 rsa.FromXmlString(gs) \'公匙 encryptedData = RSA.Encrypt(encoding.UTF8.GetBytes(DataToEncrypt), False) \'output.show("加密后:" & ByteConverter.GetString(encryptedData)) output.show("加密后:" & convert.ToBase64String(encryptedData)) \'rsa.FromXmlString(ss) \'decryptedData = RSA.Decrypt(encryptedData, False) \'output.show("解密后: " & encoding.UTF8.Getstring(decryptedData)) 遇到的问题;对方给了指定的密钥 pck ,如果不构造成 <RSAKeyValue><Modulus>" & pck & "</ 这样 程序报错,我这样构造下,可以加密,但得到的结果和在线加密得到的结果不一样 [此贴子已经被作者于2025/1/1 17:18:37编辑过]
|
-- 作者:有点蓝 -- 发布时间:2025/1/2 8:44:00 -- 接口开发文档发过来看看 |