这两段java代码,用php怎么翻译?求指点!

liziyu

片段一:

byte[] keyBytes = Base64Util.decodeBase64(privateKey);//对私钥做base64解码
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey priKey = keyFactory.generatePrivate(pkcs8KeySpec);
Signature signature = Signature.getInstance("MD5withRSA");
signature.initSign(priKey);
signature.update(data);//data为要生成签名的源数据字节数组
return Base64Util.encodeBase64(Base64Util.encodeBase64(signature.sign()).getBytes());

片段二:

byte[]publicKey=Base64Util.decodeBase64(publicKey);//对提供的公钥做base64解码
byte[] sign= Base64Util.decodeBase64(Base64Util.decodeBase64(sign))//签名需要做二次base64解码
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKey);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey pubKey = keyFactory.generatePublic(keySpec);
Signature signature = Signature.getInstance("MD5withRSA");
signature.initVerify(pubKey);
signature.update(data);
return signature.verify(sign);

头大。

1752 1 0
1个回答

nitron

太长就不写了, 参考这个吧, 注意你上面那个做了两次b64e和b64d的操作就好

https://blog.csdn.net/panjiapengfly/article/details/75318930

  • liziyu 2022-07-09

    非常感谢!!👍👍👍

年代过于久远,无法发表回答
×
🔝