mirror of
https://github.com/nextcloud/passman.git
synced 2024-09-21 07:16:23 +08:00
RSA generation in a non-blocking way
This commit is contained in:
parent
d4088e8fbe
commit
910005893d
|
@ -6,9 +6,16 @@ angular.module('passmanApp')
|
|||
$scope.active_vault = VaultService.getActiveVault();
|
||||
|
||||
$scope.generateKeys = function(length) {
|
||||
var rsa = ShareService.rsaKeyPairToPEM(ShareService.generateRSAKeys(length));
|
||||
console.log(rsa);
|
||||
$scope.active_vault.private_sharing_key = rsa.privateKey;
|
||||
$scope.active_vault.public_sharing_key = rsa.publicKey;
|
||||
// var rsa = ShareService.rsaKeyPairToPEM(ShareService.generateRSAKeys(length));
|
||||
ShareService.generateRSAKeys(length, function(progress){
|
||||
console.log(progress);
|
||||
}, function(kp){
|
||||
console.log(kp);
|
||||
});
|
||||
// console.log(rsa);
|
||||
// $scope.active_vault.private_sharing_key = rsa.privateKey;
|
||||
// $scope.active_vault.public_sharing_key = rsa.publicKey;
|
||||
// console.log(ShareService.rsaPublicKeyFromPEM(rsa.publicKey));
|
||||
// console.log(ShareService.rsaPrivateKeyFromPEM(rsa.privateKey));
|
||||
}
|
||||
}]);
|
|
@ -21,14 +21,41 @@ angular.module('passmanApp')
|
|||
}
|
||||
});
|
||||
},
|
||||
generateRSAKeys: function(key_length){
|
||||
return forge.pki.rsa.generateKeyPair(key_length);
|
||||
generateRSAKeys: function(key_length, progress, callback){
|
||||
// return forge.pki.rsa.generateKeyPair(key_length);
|
||||
|
||||
var state = forge.pki.rsa.createKeyPairGenerationState(key_length, 0x10001);
|
||||
var step = function() {
|
||||
// run for 100 ms
|
||||
if(!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) {
|
||||
console.log(state);
|
||||
console.log({
|
||||
// 'data_length': state.n.data.length,
|
||||
'bits' : state.bits,
|
||||
'pBits': state.pBits,
|
||||
'qBits': state.qBits
|
||||
});
|
||||
setTimeout(step, 1);
|
||||
}
|
||||
else {
|
||||
// done, turn off progress indicator, use state.keys
|
||||
callback(state.keys);
|
||||
}
|
||||
};
|
||||
// turn on progress indicator, schedule generation to run
|
||||
setTimeout(step);
|
||||
},
|
||||
rsaKeyPairToPEM: function(keypair){
|
||||
return {
|
||||
'publicKey' : forge.pki.publicKeyToPem(keypair.publicKey),
|
||||
'privateKey' : forge.pki.privateKeyToPem(keypair.privateKey)
|
||||
};
|
||||
},
|
||||
rsaPrivateKeyFromPEM: function(private_pem) {
|
||||
return forge.pki.privateKeyFromPem(private_pem);
|
||||
},
|
||||
rsaPublicKeyFromPEM: function(public_pem){
|
||||
return forge.pki.publicKeyFromPem(public_pem);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
|
Loading…
Reference in a new issue