现在,我只有模数和指数。
我应该如何在 PHP 中使用模数和指数进行加密?
我花了很多时间在网上寻找答案,但毫无用处。
谢谢你的时间
使用 phpseclib,一个纯粹的PHP RSA 实现 http://phpseclib.sourceforge.net/rsa/intro.html,
<?php
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$rsa->loadKey(
array(
'e' => new Math_BigInteger('...'),
'n' => new Math_BigInteger('...')
)
);
$rsa->encrypt('...');
有关 Math_BigInteger 支持的各种数字格式的讨论可以在此处找到:
http://phpseclib.sourceforge.net/math/examples.html#constructor http://phpseclib.sourceforge.net/math/examples.html#constructor
请注意,phpseclib 遵循 PKCS1 标准并填充明文。因为听起来您的 RSA 密钥没有以行业标准方式格式化,所以我猜您也不想使用行业标准填充。所以你要做的是这样的:
$plaintext = new Math_BigInteger('aaaaaa');
echo $rsa->_exponentiate($plaintext)->toBytes();
请注意,像这样进行 RSA 加密是相当不安全的,但我会将这一考虑留给您。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)