任何人都可以帮助我使用phpseclib从Java符号转换为php代码
public string SignData(string _data,string _priKey)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
rsa.FromXmlString(_priKey);
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] dataToEncrypt = ByteConverter.GetBytes(_data);
byte[] signature = rsa.SignData(dataToEncrypt,'sha256');
string result = Convert.ToBase64String(signature);
return result;
}
我正在使用它,但是(在laravel中)不起作用
use phpseclib\Crypt\RSA;
$rsa = new RSA();
$rsa->setHash('sha256');
$rsa->setSignatureMode(2);
$privateXmlKey = '<RSAKeyValue><Modulus></Modulus><Exponent>AQAB</Exponent><P></P><Q></Q><DP></DP><DQ></DQ><InverseQ></InverseQ><D></D></RSAKeyValue>';
$rsa->loadKey($privateXmlKey, 2);
$text = 'sample data';
$plainText = mb_convert_encoding($text, 'UTF-16');
$sign = $rsa->sign($plainText);
$sign = base64_encode($sign);
我尝试了两种签名模式:CRYPT_RSA_SIGNATURE_PKCS1
和CRYPT_RSA_SIGNATURE_PSS
非常感谢