2014-12-13 137 views

回答

1

RSAGenerate不採取公開密鑰,但在十六進制公鑰指數。請注意,您必須仔細選擇它,因爲它必須與φ(n)互反。爲了與其他實現兼容,一個很好的值是10001(十六進制)。

公鑰可從所述私鑰通過設置ÑË創建:

var pubkey = new RSAKey(); 
pubkey.n = privKey.n; 
pubkey.e = privKey.e; 

forge docs包含三個不同的例子的RSA密鑰對如何與相同的公共指數所產生以上:

// generate an RSA key pair synchronously 
var keypair = rsa.generateKeyPair({bits: 2048, e: 0x10001}); 
// generate an RSA key pair asynchronously (uses web workers if available) 
// use workers: -1 to run a fast core estimator to optimize # of workers 
rsa.generateKeyPair({bits: 2048, workers: 2}, function(err, keypair) { 
    // keypair.privateKey, keypair.publicKey 
}); 
// generate an RSA key pair in steps that attempt to run for a specified period 
// of time on the main JS thread 
var state = rsa.createKeyPairGenerationState(2048, 0x10001); 
var step = function() { 
    // run for 100 ms 
    if(!rsa.stepKeyPairGenerationState(state, 100)) { 
    setTimeout(step, 1); 
    } 
    else { 
    // done, turn off progress indicator, use state.keys 
    } 
}; 
// turn on progress indicator, schedule generation to run 
setTimeout(step); 
+0

但是用戶必須仔細選擇'E'嗎?庫不生成* n * s.t. 'E'與φ(* n *)互質? – Kar 2014-12-13 09:32:35

+0

是的,用戶必須選擇它,但爲了與其他實現兼容,通常將其設置爲0x10001。 – 2014-12-13 09:36:00

+0

我明白了。那麼堅持到0x10001是否安全? – Kar 2014-12-13 10:02:18