英文:
Golang to PHP Script for decryption
问题
我正在尝试解密来自Wallester加密的卡号结果。我从他们的支持中获得了解密的信息,但是是用Golang编写的,我试图使用phpseclib将其翻译成PHP,但失败了。
以下是使用phpseclib版本2的PHP代码示例:
$rsa = new RSA();
$rsa->loadKey(file_get_contents(APPPATH . 'rsa/private.pem'));
$decryptedCardNumber = $rsa->decrypt($encryptedCardNumber, RSA::ENCRYPTION_OAEP, $label = 'CardNumber');
echo $decryptedCardNumber;
示例数据加密如下:
-----BEGIN CardNumber MESSAGE-----
ZGus1SGZCnsT7xoZKW1O8RXf3A+8dL6lf6TjsTqr3pgHHZpmFhJX0g8ZSGELPo9M
ILWg/jZag2vX7hwICILOJ3jxm0zwKpL4Gft4cUpnAK42NZakZUwPc7IZSQtRMhHI
jv3H135bJ9YBUOx/cJ1mLDKBcMPGUjwvikw/R3KKWBLViT4Og22K1WJp7w9FqrIy
Ucd65mh/jMGmbwIk9vuh90rxf3RHnykiuaHgE+f/hx3IDN7Glbxi2uivgO6C0sZE
PAdLi3RkIjo18VR9jzCobQ+mFwqcXHFQxO+FLU4CsTf7SyKzaDgnrsJIMyCIax04
QN79qabV91gSoqs1quL9NeRWCmsaWXKPeDMkCumrAxSjhkxcU7iM8S/ubG70Qr7Z
BsCnTCInuSqoQNu2soveU1m8t0+tq6q3JUnHq/AeegYsxsXjPO+1a0CvqpXLsDqi
0Vc2dy5SUmb1N9jpdIXIF17MtY5nY70pu7WaeEAWk/JqGGwED3aolmjO++f2upz1
Xzp0w1Sn5IYYKCxamV9JK+XCUS/XwIAphGCiJZOB0Oo36jgEAlQkJO4LYV8Xmv+D
2ntL8DtRrWg8z8qbA759uv+1CN5EzbLh9t1hGhdncDLpyQWqg1y0loHRXJ19z6Ik
WY/1RjBSxGFPpVHSB7j84JMp6NgbLItoBD2oUXr0IZo=
-----END CardNumber MESSAGE-----
有人知道在PHP中有类似的Golang函数吗?
英文:
I'm trying to decrypt result from wallester encrypted card number.
I've got an information how to decrypt from their support but in golang, and try to translate it using phpseclib but it failed.
var resp model.GetEncryptedCardNumberResponse
rsa := crypto.NewRSA([]byte(rsaPrivateKey))
decryptedCardNumber := rsa.DecryptOAEPFromPEM(resp.EncryptedCardNumber, crypto.LabelCardNumber)
log.Println(fmt.Sprintf("Decrypted card number: %s", decryptedCardNumber))
here my php using phpseclib version 2
$rsa = new RSA();
$rsa->loadKey(file_get_contents(APPPATH .'rsa/private.pem'));
$decryptedCardNumber = $rsa->decrypt($encryptedCardNumber, RSA::ENCRYPTION_OAEP, $label = 'CardNumber');
echo decryptedCardNumber;
example data encrypted:
-----BEGIN CardNumber MESSAGE-----
ZGus1SGZCnsT7xoZKW1O8RXf3A+8dL6lf6TjsTqr3pgHHZpmFhJX0g8ZSGELPo9M
ILWg/jZag2vX7hwICILOJ3jxm0zwKpL4Gft4cUpnAK42NZakZUwPc7IZSQtRMhHI
jv3H135bJ9YBUOx/cJ1mLDKBcMPGUjwvikw/R3KKWBLViT4Og22K1WJp7w9FqrIy
Ucd65mh/jMGmbwIk9vuh90rxf3RHnykiuaHgE+f/hx3IDN7Glbxi2uivgO6C0sZE
PAdLi3RkIjo18VR9jzCobQ+mFwqcXHFQxO+FLU4CsTf7SyKzaDgnrsJIMyCIax04
QN79qabV91gSoqs1quL9NeRWCmsaWXKPeDMkCumrAxSjhkxcU7iM8S/ubG70Qr7Z
BsCnTCInuSqoQNu2soveU1m8t0+tq6q3JUnHq/AeegYsxsXjPO+1a0CvqpXLsDqi
0Vc2dy5SUmb1N9jpdIXIF17MtY5nY70pu7WaeEAWk/JqGGwED3aolmjO++f2upz1
Xzp0w1Sn5IYYKCxamV9JK+XCUS/XwIAphGCiJZOB0Oo36jgEAlQkJO4LYV8Xmv+D
2ntL8DtRrWg8z8qbA759uv+1CN5EzbLh9t1hGhdncDLpyQWqg1y0loHRXJ19z6Ik
WY/1RjBSxGFPpVHSB7j84JMp6NgbLItoBD2oUXr0IZo=
-----END CardNumber MESSAGE-----
anyone know similar function golang in PHP?
答案1
得分: 1
最后我找到了解决方案
这是我的脚本来解密卡号
首先清理结果
$encrypted=str_replace("-----BEGIN CardNumber MESSAGE-----","",$encrypted);
$encrypted=str_replace("-----END CardNumber MESSAGE-----", "",$encrypted);
$encrypted=str_replace("\n", "",$encrypted);
开始解码(我使用phpseclib3)
$private = PublicKeyLoader::load(file_get_contents('/path/to/key.pem'));
$plaintext = $private->withLabel("CardNumber")->decrypt(base64_decode($encrypted));
echo $plaintext;
并获取明文
英文:
Finally I found solution
Here my script to get decrypt the card number
first I clean the result
$encrypted=str_replace("-----BEGIN CardNumber MESSAGE-----","",$encrypted);
$encrypted=str_replace("-----END CardNumber MESSAGE-----", "",$encrypted);
$encrypted=str_replace("\n", "",$encrypted);
Start to decode (I'm using phpseclib3)
$private = PublicKeyLoader::load(file_get_contents('/path/to/key.pem'));
$plaintext = $private->withLabel("CardNumber")->decrypt(base64_decode($encrypted));
echo $plaintext;
And get the plaintext
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论