我尝试使用openssl_public_decrypt解密并失败.openssl_public_decrypt不会返回任何内容。我不知道问题出在哪里,下面是我的代码。 我尝试不使用base64_encode,也无法正常工作。我需要从数据库中读取rsa键值。
<?php
$data = 'data to be encrypt';
echo $data;
$privateKey = '-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDJDA1AKIHIoj+a
roYVXoBogXfmIbArgiuvjJ2p87XN1pPs4YUC1dyZcdG+ULBtPaApLOsw0tNnNAjT
N3MWTIi9QD+NfD/BT6t44iWuqx9ryWy35H7yF1b92jEAMzCQ4uXaStZN3nzSoCvk
RB3iB4W4VSI/bBgaM2Q9B3mE11VJDzdcuQ6nMivIASRF5f/w05324i7ElCH521E6
2iKK63USOnNG29XH4fSL5+jC3bju/bafakb7oB148TZhf4ueCxVvK7j/enHFPKZi
Cm4qA42JgZNvXDkOixBtzDUmR+ULBr7Vt0b5Isa0Zt6845LXyRmOSwQ5W5f3H77+
JYMNSIWRO0Ola8HEkJuwCohmjcN2txVNJQjjNMZZCJ7+uj13N9rIUDsloO1KMm59
Q3yeh4qkvC0Te2C0WNGrAp952Sq5Hva7HB5K0l1wQ7l2U4oAds4V3eT60iDLcrWe
AvWEFQWjncU7ITwgZ+kFysP22TSFjl3WJZiPmcOrX/OJdKQpwxavganu3Bmpf4Tg
e5L4LWswnkTzKd9J9tN/YGyoJEe9/dkwovjJsPKBKFoqfCHsI8HqULVzkhO5whTF
921ly9qSbmBw2al8tbms46za2MHTPDqE7GtQ10CTO4G08kCs/V8Yb22us3GqxL7q
G6j6wWtrQsqYPwnZicgh8hsFeMNCiQIDAQABAoICACRsM4ZZEFIp2r4KOi5q5XaJ
ZhBiMAlh1spB/lpI1boJ0tjKbo958TI3ZZlGAwB3dqmfAqjguP3sdmDVndr/WJJ4
rkrSpLY/2b/XsJ35UIL1heW21qzDP7ZTribsHzNQd/XZMwP+d7ys2ebL1GIbnMUt
XzwAOEme390SmphPbpsCz7P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41Ywc
/pMjAStbV7/lTR9QYRtZHPsqyQgzjUDzLGFQffpDLGXNHBfIVoNKLuCOyfekcIo+
oBdPnE4O8GrJkQLQhBiT5KxBGFD0H7aBlMH8dwMaaLhhBoelONH5wyhElKVg4tL2
INRxom+wANYnRDgMh9QWURpJGVbpEA==
-----END PRIVATE KEY-----';
openssl_private_encrypt($data, $encrypted, $privateKey);
echo '-------------';
echo $encrypted;
echo '-------------';
$encrypted = base64_encode($encrypted);
echo $encrypted;
echo '-------------';
$publicKey = '-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsZka5Mul/211/0h84Ig8
i8lJVy21tvFN8uTRKgldY3TMfcdiQjLXNXXWVBdcobXa9wzNx3YXvyqr3Tnmr0iN
loVovJ9JER5EUQPEPthMNn9de9fEgNsfABT0Eq2291t8sFMx1/mAHd6z8KE+mzYC
yVeZqLEmwsiKCMjx1Pj2NfGR9+bNfC5P0SG2ARdpFZFJL6XK7L6t+nW9HXcDwPP1
ocA38iSjovjyel/LP00zETL3z0wlIPzxMCodxUU/bPdlDGQbc1MzaYHvOP+RXVFZ
j5fEp9OFpbm6BJXi/RT3/PYWS7+RCUHsb+LSa1JLylsEzyNaKqYX+wY0/2hEcWB3
WcYP6QRF/EKSLQbB7EvMucUM79deTkmFrly4ePkrk5tPoiQzRXFkoSGM4nKxAh0T
6Sjg8/WchBpVJQRvU+9vb9yk2Tey045/Wo3G1Fvehs/OXcd5P7OPLLpmLMNve7oZ
DVaw8lHBIxjMtAz+pZKvxDDtJR9jZuaiBqyGjj7rHnvagrxhZmdQiIDuuCOdaqTk
ARGrtgsLmIPbsO6HukkyG6W+8RjtVb+M2yC7HjFcwWcwBLe5mj0gikFe6wk0GtTJ
i1KdWoxjgibvWR9PRLKKlqT+CC0xgitln8PbH0xWNj7NlmMPdBuaN7Dpu8MU9ejS
6N3vOIsj40M0pgv6fdufnK8CAwEAAQ==
-----END PUBLIC KEY-----';
$decryptData = base64_decode($encrypted);
echo $decryptData;
echo '-------------';
openssl_public_decrypt($decryptData, $decrypted, $publicKey);
echo $decrypted;
我想知道出了什么问题。我需要您的帮助。