I'm trying to port the following php functionality over to perl:
我试图将以下php功能移植到perl:
public function loadKey($mod, $exp, $type = 'public')
{
$rsa = new Crypt_RSA();
$rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
$rsa->setHash('sha256');
$rsa->modulus = new Math_BigInteger(Magicsig::base64_url_decode($mod), 256);
$rsa->k = strlen($rsa->modulus->toBytes());
$rsa->exponent = new Math_BigInteger(Magicsig::base64_url_decode($exp), 256);
// snip...
}
I need to convert a string in the form ("RSA.$mod.$exp.$private_exp"):
我需要转换表单中的字符串(“RSA.$mod.$exp.$private_exp”):
RSA.mVgY8RN6URBTstndvmUUPb4UZTdwvwmddSKE5z_jvKUEK6yk1u3rrC9yN8k6FilGj9K0eeUPe2hf4Pj-5CmHww==.AQAB.Lgy_yL3hsLBngkFdDw1Jy9TmSRMiH6yihYetQ8jy-jZXdsZXd8V5ub3kuBHHk4M39i3TduIkcrjcsiWQb77D8Q==
...to a Crypt::RSA object. I've split out the components so I have $mod, $exp, and $private_exp, but the perl Crypt::RSA API doesn't seem to have a way to explicitly set.
…地下室::RSA对象。我划分了组件,所以我有$mod、$exp和$private_exp,但是perl Crypt::RSA API似乎没有明确设置的方法。
1 个解决方案
#1
5
Worked out on IRC, documenting it here for the rest of the world: it's completely undocumented but Crypt::RSA::Key
does have methods called n
, e
, and d
that correspond to the modulus, the public exponent, and the private exponent. Modulo bugs in the check function (which is supposed to work if p
and q
are unavailable but n
is, but actually doesn't), it's possible to create a working key with those methods.
对IRC进行了研究,并在这里为世界其他地方做了记录:它是完全无证的,但是Crypt::RSA: Key有一些方法叫做n, e,和d,它们对应于模量,公共指数和私有指数。检查函数中的Modulo错误(如果p和q不可用但n不可用,但实际上不能),可以使用这些方法创建一个工作键。
We solved the problem together by creating a subclass of Crypt::RSA::Key::Private
with a factory method that decodes the base64 encoding (using MIME::Base64::URLSafe) and the additional binary encoding (using Math::BigInt->from_hex and unpack "H*"
) and then sets those three private members, and the Crypt::RSA
modules were able to accept it as a Key.
我们一起解决了这个问题通过创建一个子类的地下室::RSA::关键::私人的工厂方法解码base64编码(使用MIME::base64::URLSafe)和额外的二进制编码(使用数学::BigInt - > from_hex和打开“H *”),然后设置这三个私有成员,和地下::RSA模块能够接受它作为一个关键。
#1
5
Worked out on IRC, documenting it here for the rest of the world: it's completely undocumented but Crypt::RSA::Key
does have methods called n
, e
, and d
that correspond to the modulus, the public exponent, and the private exponent. Modulo bugs in the check function (which is supposed to work if p
and q
are unavailable but n
is, but actually doesn't), it's possible to create a working key with those methods.
对IRC进行了研究,并在这里为世界其他地方做了记录:它是完全无证的,但是Crypt::RSA: Key有一些方法叫做n, e,和d,它们对应于模量,公共指数和私有指数。检查函数中的Modulo错误(如果p和q不可用但n不可用,但实际上不能),可以使用这些方法创建一个工作键。
We solved the problem together by creating a subclass of Crypt::RSA::Key::Private
with a factory method that decodes the base64 encoding (using MIME::Base64::URLSafe) and the additional binary encoding (using Math::BigInt->from_hex and unpack "H*"
) and then sets those three private members, and the Crypt::RSA
modules were able to accept it as a Key.
我们一起解决了这个问题通过创建一个子类的地下室::RSA::关键::私人的工厂方法解码base64编码(使用MIME::base64::URLSafe)和额外的二进制编码(使用数学::BigInt - > from_hex和打开“H *”),然后设置这三个私有成员,和地下::RSA模块能够接受它作为一个关键。