mirror of
https://github.com/nextcloud/passman.git
synced 2024-11-14 20:06:17 +08:00
40 lines
952 B
JavaScript
40 lines
952 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @ngdoc service
|
|
* @name passmanApp.EncryptService
|
|
* @description
|
|
* # EncryptService
|
|
* Service in the passmanApp.
|
|
*/
|
|
angular.module('passmanApp')
|
|
.service('EncryptService', ['VaultService', function (VaultService) {
|
|
// AngularJS will instantiate a singleton by calling "new" on this function
|
|
var encryption_config = {
|
|
adata:"",
|
|
iter: 1000,
|
|
ks: 256,
|
|
mode: 'ccm',
|
|
ts:64
|
|
};
|
|
|
|
return {
|
|
encryptString: function(string){
|
|
var _key = VaultService.getActiveVault().vaultKey;
|
|
var rp = {};
|
|
var ct = sjcl.encrypt(_key, string, encryption_config, rp);
|
|
return window.btoa(ct);
|
|
},
|
|
decryptString: function(ciphertext){
|
|
ciphertext = window.atob(ciphertext);
|
|
var _key = VaultService.getActiveVault().vaultKey;
|
|
var rp = {};
|
|
try {
|
|
return sjcl.decrypt(_key, ciphertext, encryption_config, rp)
|
|
} catch(e) {
|
|
Error("Can't decrypt: "+e);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}]);
|