templates_js/evernote/decrypt.js
/**
             * Same as decrypt, but calls SJCL methods to break up CPU intensive operations into
             * separate browser event loop calls for the benefit of older browsers, such as IE7
             * and IE8.
             */
Same as decrypt, but calls SJCL methods to break up CPU intensive operations into
separate browser event loop calls for the benefit of older browsers, such as IE7
and IE8.
Same as decrypt but calls SJCL methods to break up CPU intensive operations into separate browser event loop calls for the benefit of older browsers such as IE7 and IE8 .
function decrypt_async(password, data) {
                try {
                  if (typeof data === 'string') {
                      data = sjcl.codec.base64.toBits(data);
                  }
                  var cursor = BYTE_LEN * EN_IDENT.length;
                  if (EN_IDENT !== sjcl.codec.utf8String.fromBits([data[0]])) {
                      DEBUG && en.console.error('No Evernote crypto data.');
                      throw 'This is not Evernote crypto data.';
                  }
                  var salt = sjcl.bitArray.bitSlice(data, cursor, cursor + EN_KEYSIZE);
                  cursor += EN_KEYSIZE;
                  var saltHMAC = sjcl.bitArray.bitSlice(data, cursor, cursor + EN_KEYSIZE);
                  cursor += EN_KEYSIZE;
                  var iv = sjcl.bitArray.bitSlice(data, cursor, cursor + EN_KEYSIZE);
                  cursor += EN_KEYSIZE;
                  var dataLen = sjcl.bitArray.bitLength(data);
                  var ct = sjcl.bitArray.bitSlice(data, cursor, dataLen - EN_HMACSIZE);
                  cursor += dataLen - EN_HMACSIZE - cursor;
                  var hmacExpected = sjcl.bitArray.bitSlice(data, cursor, cursor + EN_HMACSIZE);
                  return calcKey_async(password, saltHMAC).then(function(keyHMAC) {
                    try{
                      var hmac = new sjcl.misc.hmac(keyHMAC).encrypt(sjcl.bitArray.bitSlice(data,
                          0, dataLen - EN_HMACSIZE));
                      if (!sjcl.bitArray.equal(hmac, hmacExpected)) {
                          DEBUG && en.console.error('Invalid checksum.', hmac, hmacExpected);
                          throw 'Invalid checksum.';
                      }
                      return calcKey_async(password, salt);
                    } catch (e) {
                      return $.Deferred().reject(e);
                    }
                  }).then(function(key) {
                    try {
                      var prp = new sjcl.cipher.aes(key);
                      var result = sjcl.mode.cbc.decrypt(
                          prp,
                          ct,
                          iv
                          );
                      return sjcl.codec.utf8String.fromBits(result);
                    } catch (e) {
                      return $.Deferred().reject(e);
                    }
                  });
                } catch (e) {
                  return $.Deferred().reject(e);
                }
            }
function decrypt_async ( password , data ) { try { if ( typeof data === 'string' ) { data = sjcl . codec . base64 . toBits ( data ) ; } var cursor = BYTE_LEN * EN_IDENT . length ; if ( EN_IDENT !== sjcl . codec . utf8String . fromBits ( [ data [ 0 ] ] ) ) { DEBUG && en . console . error ( 'No Evernote crypto data.' ) ; throw 'This is not Evernote crypto data.' ; } var salt = sjcl . bitArray . bitSlice ( data , cursor , cursor + EN_KEYSIZE ) ; cursor += EN_KEYSIZE ; var saltHMAC = sjcl . bitArray . bitSlice ( data , cursor , cursor + EN_KEYSIZE ) ; cursor += EN_KEYSIZE ; var iv = sjcl . bitArray . bitSlice ( data , cursor , cursor + EN_KEYSIZE ) ; cursor += EN_KEYSIZE ; var dataLen = sjcl . bitArray . bitLength ( data ) ; var ct = sjcl . bitArray . bitSlice ( data , cursor , dataLen - EN_HMACSIZE ) ; cursor += dataLen - EN_HMACSIZE - cursor ; var hmacExpected = sjcl . bitArray . bitSlice ( data , cursor , cursor + EN_HMACSIZE ) ; return calcKey_async ( password , saltHMAC ) . then ( function ( keyHMAC ) { try { var hmac = new sjcl . misc . hmac ( keyHMAC ) . encrypt ( sjcl . bitArray . bitSlice ( data , 0 , dataLen - EN_HMACSIZE ) ) ; if ( ! sjcl . bitArray . equal ( hmac , hmacExpected ) ) { DEBUG && en . console . error ( 'Invalid checksum.' , hmac , hmacExpected ) ; throw 'Invalid checksum.' ; } return calcKey_async ( password , salt ) ; } catch ( e ) { return $ . Deferred ( ) . reject ( e ) ; } } ) . then ( function ( key ) { try { var prp = new sjcl . cipher . aes ( key ) ; var result = sjcl . mode . cbc . decrypt ( prp , ct , iv ) ; return sjcl . codec . utf8String . fromBits ( result ) ; } catch ( e ) { return $ . Deferred ( ) . reject ( e ) ; } } ) ; } catch ( e ) { return $ . Deferred ( ) . reject ( e ) ; } }
Same as decrypt, but calls SJCL methods to break up CPU intensive operations into
 separate browser event loop calls for the benefit of older browsers, such as IE7
 and IE8.
Same as decrypt but calls SJCL methods to break up CPU intensive operations into separate browser event loop calls for the benefit of older browsers such as IE7 and IE8 .
// var info = sjcl.bitArray.bitSlice(data, 0, cursor); // Check validity // Decrypt