Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.decrypt = function(data, password, pbkdf2_iterations, success, error) {
- //iso10126 with pbkdf2_iterations iterations
- try {
- var decoded = Crypto.AES.decrypt(data, password, { mode: new Crypto.mode.CBC(Crypto.pad.iso10126), iterations : pbkdf2_iterations});
- if (decoded != null && decoded.length > 0) {
- if (success(decoded)) {
- return decoded;
- };
- };
- } catch (e) {
- console.log(e);
- }
- //iso10126 with 10 iterations (old default)
- if (pbkdf2_iterations != 10) {
- try {
- var decoded = Crypto.AES.decrypt(data, password, { mode: new Crypto.mode.CBC(Crypto.pad.iso10126), iterations : 10 });
- if (decoded != null && decoded.length > 0) {
- if (success(decoded)) {
- return decoded;
- };
- };
- } catch (e) {
- console.log(e);
- }
- }
- //Otherwise try the old default settings
- try {
- var decoded = Crypto.AES.decrypt(data, password);
- if (decoded != null && decoded.length > 0) {
- if (success(decoded)) {
- return decoded;
- };
- };
- } catch (e) {
- console.log(e);
- }
- //OFB iso7816 padding with one iteration (old default)
- try {
- var decoded = Crypto.AES.decrypt(data, password, {mode: new Crypto.mode.OFB(Crypto.pad.iso7816), iterations : 1});
- if (decoded != null && decoded.length > 0) {
- if (success(decoded)) {
- return decoded;
- };
- };
- } catch (e) {
- console.log(e);
- }
- //iso10126 padding with one iteration (old default)
- try {
- var decoded = Crypto.AES.decrypt(data, password, { mode: new Crypto.mode.CBC(Crypto.pad.iso10126), iterations : 1 });
- if (decoded != null && decoded.length > 0) {
- if (success(decoded)) {
- return decoded;
- };
- };
- } catch (e) {
- console.log(e);
- }
- if (error) error();
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement