|
1
|
|
|
/** |
|
2
|
|
|
* Nextcloud - passman |
|
3
|
|
|
* |
|
4
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
|
5
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
|
6
|
|
|
* @license GNU AGPL version 3 or any later version |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
11
|
|
|
* License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
(function () { |
|
24
|
|
|
'use strict'; |
|
25
|
|
|
/** |
|
26
|
|
|
* @ngdoc service |
|
27
|
|
|
* @name passmanApp.EncryptService |
|
28
|
|
|
* @description |
|
29
|
|
|
* # EncryptService |
|
30
|
|
|
* Service in the passmanApp. |
|
31
|
|
|
*/ |
|
32
|
|
|
angular.module('passmanApp') |
|
33
|
|
|
.service('EncryptService', ['VaultService', function (VaultService) { |
|
34
|
|
|
// AngularJS will instantiate a singleton by calling "new" on this function |
|
35
|
|
|
var encryption_config = { |
|
36
|
|
|
adata: "", |
|
37
|
|
|
iter: 1000, |
|
38
|
|
|
ks: 256, |
|
39
|
|
|
mode: 'ccm', |
|
40
|
|
|
ts: 64 |
|
41
|
|
|
}; |
|
42
|
|
|
|
|
43
|
|
|
return { |
|
44
|
|
|
encryptString: function (string, _key) { |
|
45
|
|
|
if (!_key) { |
|
46
|
|
|
_key = VaultService.getActiveVault().vaultKey; |
|
47
|
|
|
} |
|
48
|
|
|
var rp = {}; |
|
49
|
|
|
/** global: sjcl */ |
|
50
|
|
|
var ct = sjcl.encrypt(_key, string, encryption_config, rp); |
|
51
|
|
|
return window.btoa(ct); |
|
52
|
|
|
}, |
|
53
|
|
|
decryptString: function (ciphertext, _key) { |
|
54
|
|
|
if (!_key) { |
|
55
|
|
|
_key = VaultService.getActiveVault().vaultKey; |
|
56
|
|
|
} |
|
57
|
|
|
ciphertext = window.atob(ciphertext); |
|
58
|
|
|
var rp = {}; |
|
59
|
|
|
try { |
|
60
|
|
|
/** global: sjcl */ |
|
61
|
|
|
return sjcl.decrypt(_key, ciphertext, encryption_config, rp); |
|
62
|
|
|
} catch (e) { |
|
63
|
|
|
throw e; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
}; |
|
68
|
|
|
}]); |
|
69
|
|
|
}()); |