// Generated by CoffeeScript 1.6.3
var YASGGCrypto, exports;

YASGGCrypto = (function() {
  var _header_field_bytes, _key, _salt;

  _salt = void 0;

  _key = void 0;

  _header_field_bytes = 40;

  function YASGGCrypto(password_hashed) {
    var self;
    self = this;
    self._key = CryptoJS.enc.Latin1.parse(password_hashed);
  }

  YASGGCrypto.prototype.key_get = function() {
    return this._key;
  };

  YASGGCrypto.prototype.decrypt = function(enrypted_data) {
    var decrypted, encrypted, self;
    self = this;
    encrypted = {};
    encrypted.checksum = CryptoJS.enc.Hex.parse(enrypted_data.substr(_header_field_bytes, _header_field_bytes).trim()).toString();
    encrypted.iv = CryptoJS.enc.Hex.parse(enrypted_data.substr(_header_field_bytes * 2, _header_field_bytes).trim());
    encrypted.ciphertext = CryptoJS.enc.Hex.parse(enrypted_data.substr(_header_field_bytes * 3));
    decrypted = {};
    decrypted.data = CryptoJS.AES.decrypt(encrypted, self.key_get(), {
      iv: encrypted.iv,
      padding: CryptoJS.pad.Pkcs7,
      method: CryptoJS.pad.CBC
    });
    decrypted.checksum = encrypted.checksum;
    return decrypted;
  };

  return YASGGCrypto;

})();

exports = this;

exports.YASGGCrypto = YASGGCrypto;
