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

时间:2014-07-17 15:32:13

标签: 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,$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中解密工作正常

1 个答案:

答案 0 :(得分:0)

没关系

使用utf8代替unicode 更改

来解决它
Dim uEncode As New UnicodeEncoding()

Dim uEncode As New UTF8Encoding()