Advertisement
Guest User

Untitled

a guest
Sep 29th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. this.decrypt = function(data, password, pbkdf2_iterations, success, error) {
  2.         //iso10126 with pbkdf2_iterations iterations
  3.         try {
  4.             var decoded = Crypto.AES.decrypt(data, password, { mode: new Crypto.mode.CBC(Crypto.pad.iso10126), iterations : pbkdf2_iterations});
  5.  
  6.             if (decoded != null && decoded.length > 0) {
  7.                 if (success(decoded)) {
  8.                     return decoded;
  9.                 };
  10.             };
  11.         } catch (e) {
  12.             console.log(e);
  13.         }
  14.  
  15.         //iso10126 with 10 iterations  (old default)
  16.         if (pbkdf2_iterations != 10) {
  17.             try {
  18.                 var decoded = Crypto.AES.decrypt(data, password, { mode: new Crypto.mode.CBC(Crypto.pad.iso10126), iterations : 10 });
  19.  
  20.                 if (decoded != null && decoded.length > 0) {
  21.                     if (success(decoded)) {
  22.                         return decoded;
  23.                     };
  24.                 };
  25.             } catch (e) {
  26.                 console.log(e);
  27.             }
  28.         }
  29.  
  30.         //Otherwise try the old default settings
  31.         try {
  32.             var decoded = Crypto.AES.decrypt(data, password);
  33.  
  34.             if (decoded != null && decoded.length > 0) {
  35.                 if (success(decoded)) {
  36.                     return decoded;
  37.                 };
  38.             };
  39.         } catch (e) {
  40.             console.log(e);
  41.         }
  42.  
  43.         //OFB iso7816 padding with one iteration (old default)
  44.         try {
  45.             var decoded = Crypto.AES.decrypt(data, password, {mode: new Crypto.mode.OFB(Crypto.pad.iso7816), iterations : 1});
  46.  
  47.             if (decoded != null && decoded.length > 0) {
  48.                 if (success(decoded)) {
  49.                     return decoded;
  50.                 };
  51.             };
  52.         } catch (e) {
  53.             console.log(e);
  54.         }
  55.  
  56.         //iso10126 padding with one iteration (old default)
  57.         try {
  58.             var decoded = Crypto.AES.decrypt(data, password, { mode: new Crypto.mode.CBC(Crypto.pad.iso10126), iterations : 1 });
  59.  
  60.             if (decoded != null && decoded.length > 0) {
  61.                 if (success(decoded)) {
  62.                     return decoded;
  63.                 };
  64.             };
  65.         } catch (e) {
  66.             console.log(e);
  67.         }
  68.  
  69.         if (error) error();
  70.  
  71.         return null;
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement