簡體   English   中英

JavaScript中的RSA與PHP不同

[英]RSA in javascript different from PHP

我現在對RSA有問題。 我在Javascript和PHP中具有相同的模數和指數。在JavaScript中都使用PKCS#1,我使用http://www-cs-students.stanford.edu/~tjw/jsbn/rsa.js

var rsa = new RSAKey();
rsa.setPublic("modulus","ex");
var result = rsa.encrypt(text);

在PHP中,我使用http://phpseclib.sourceforge.net/

require_once 'Crypt/RSA.php';
$rsa = new Crypt_RSA();
$n="modulus";
$e="ex";
$rsa->modulus= new Math_BigInteger($n,16);
$rsa->publicExponent= new Math_BigInteger($e,16);
$key=$rsa->getPublicKey();
$rsa->loadKey($key);
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = $rsa->encrypt("1234");
echo bin2hex($ciphertext);

但是2結果不同。 可以請告訴我原因。 非常感謝你

它們不同,因為PKCS#1采用隨機填充。

查看以下URL:

http://www-cs-students.stanford.edu/~tjw/jsbn/rsa.html

多次點擊加密。 每次得到的密文都會不同。

重要的是您可以解密它-而不是密文不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM