mirror of
https://github.com/nextcloud/passman.git
synced 2025-11-10 22:22:38 +08:00
RSA generation in a non-blocking way
This commit is contained in:
parent
d4088e8fbe
commit
910005893d
2 changed files with 40 additions and 6 deletions
|
|
@ -6,9 +6,16 @@ angular.module('passmanApp')
|
||||||
$scope.active_vault = VaultService.getActiveVault();
|
$scope.active_vault = VaultService.getActiveVault();
|
||||||
|
|
||||||
$scope.generateKeys = function(length) {
|
$scope.generateKeys = function(length) {
|
||||||
var rsa = ShareService.rsaKeyPairToPEM(ShareService.generateRSAKeys(length));
|
// var rsa = ShareService.rsaKeyPairToPEM(ShareService.generateRSAKeys(length));
|
||||||
console.log(rsa);
|
ShareService.generateRSAKeys(length, function(progress){
|
||||||
$scope.active_vault.private_sharing_key = rsa.privateKey;
|
console.log(progress);
|
||||||
$scope.active_vault.public_sharing_key = rsa.publicKey;
|
}, 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){
|
generateRSAKeys: function(key_length, progress, callback){
|
||||||
return forge.pki.rsa.generateKeyPair(key_length);
|
// 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){
|
rsaKeyPairToPEM: function(keypair){
|
||||||
return {
|
return {
|
||||||
'publicKey' : forge.pki.publicKeyToPem(keypair.publicKey),
|
'publicKey' : forge.pki.publicKeyToPem(keypair.publicKey),
|
||||||
'privateKey' : forge.pki.privateKeyToPem(keypair.privateKey)
|
'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…
Add table
Reference in a new issue