dsgrs26202 2013-11-29 16:05
浏览 246
已采纳

PHP:RSA仅使用模数和指数加密

now , i ONLY have the modulus and exponent.

How should i do to encrypt using modulus and exponent in PHP?

It costed me much time that serching the answer in internet, but all was useless.

Thanks for your time

  • 写回答

1条回答 默认 最新

  • dongzhi1949 2013-11-29 18:45
    关注

    Using phpseclib, a pure PHP RSA implementation,

    <?php
    include('Crypt/RSA.php');
    
    $rsa = new Crypt_RSA(); 
    $rsa->loadKey(
        array(
            'e' => new Math_BigInteger('...'),
            'n' => new Math_BigInteger('...')
        )
    );
    
    $rsa->encrypt('...');
    

    A discussion of the various number formats supported by Math_BigInteger can be found here:

    http://phpseclib.sourceforge.net/math/examples.html#constructor

    Note that phpseclib follows the PKCS1 standards and pads plaintext's. Since it sounds like your RSA key isn't formated in an industry standard way I'm going to guess you're not wanting to use industry standard padding either. So what you'll want to do is this:

    $plaintext = new Math_BigInteger('aaaaaa');
    echo $rsa->_exponentiate($plaintext)->toBytes();
    

    Do note that doing RSA encryption like that is quite insecure but I'll leave that consideration up to you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办