在vb.net中通过php加密Rsa并给出符号

在vb.net中通过php加密Rsa并给出符号,php,vb.net,encryption,rsa,Php,Vb.net,Encryption,Rsa,我试图用php加密字符串,用vb.net解密它 相同密钥(xml转换为pem) 这是我的php代码 $source = "Baselsayeh!@#312"; echo "Source: $source"; $fp=fopen("publicKey.pem","r"); $pub_key=fread($fp,8192); fclose($fp); openssl_get_publickey($pub_key); $hh = $source; openssl_public_encrypt($hh,

我试图用php加密字符串,用vb.net解密它

相同密钥(xml转换为pem)

这是我的php代码

$source = "Baselsayeh!@#312";
echo "Source: $source";
$fp=fopen("publicKey.pem","r");
$pub_key=fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
$hh = $source;
openssl_public_encrypt($hh,$crypttext,$pub_key);
$crypttext = base64_encode($crypttext);
echo "String crypted: " . $crypttext;
这是我的vb.net代码

Function Decrypt(ByVal strCipherText As String, _
ByVal strPrivateKey As String) As String
    Dim rsa As New RSACryptoServiceProvider()
    Dim bytPlainText() As Byte
    Dim bytCipherText() As Byte
    Dim uEncode As New UnicodeEncoding()
    rsa.FromXmlString(strPrivateKey)
    bytCipherText = Convert.FromBase64String(strCipherText)
    bytPlainText = rsa.Decrypt(bytCipherText, False)
    Decrypt = uEncode.GetString(bytPlainText)
    rsa.Clear()
End Function
任何加密字符串慂敳獬祡桥䀡㌣㈱

但是vb.net中的加密和php中的解密都很好

没关系

使用unicode的utf8 instaid解决了这个问题

改变

Dim uEncode As New UnicodeEncoding()


什么是字符编码?这两个系统中的密码是否相同?这意味着要么加密错误,要么解密错误。密码算法并不关心密钥是否正确。这基本上只是数学,完全取决于你提供正确的数字,使所有的“工作”。这也意味着像一边是b64编码,另一边不是b64解码这样的事情可能会影响所有这一切
Dim uEncode As New UTF8Encoding()