rncryptor-test.js 1.5 KB

123456789101112131415161718192021222324
  1. var verify_kdf = function(vector) {
  2. var key = RNCryptor.KeyForPassword(vector["password"], sjcl.codec.hex.toBits(vector["salt_hex"]));
  3. equal(sjcl.codec.hex.fromBits(key), vector["key_hex"].replace(/\s/g,''));
  4. }
  5. var verify_password = function(vector) {
  6. var ciphertext = RNCryptor.Encrypt(vector["password"],
  7. sjcl.codec.hex.toBits(vector["plaintext_hex"].replace(/\s/g,'')),
  8. { "encryption_salt": sjcl.codec.hex.toBits(vector["enc_salt_hex"].replace(/\s/g,'')),
  9. "hmac_salt": sjcl.codec.hex.toBits(vector["hmac_salt_hex"].replace(/\s/g,'')),
  10. "iv": sjcl.codec.hex.toBits(vector["iv_hex"].replace(/\s/g,''))
  11. });
  12. equal(sjcl.codec.hex.fromBits(ciphertext), vector["ciphertext_hex"].replace(/\s/g,''));
  13. var plaintext = RNCryptor.Decrypt(vector["password"],
  14. sjcl.codec.hex.toBits(vector["ciphertext_hex"].replace(/\s/g,'')),
  15. { "encryption_salt": sjcl.codec.hex.toBits(vector["enc_salt_hex"].replace(/\s/g,'')),
  16. "hmac_salt": sjcl.codec.hex.toBits(vector["hmac_salt_hex"].replace(/\s/g,'')),
  17. "iv": sjcl.codec.hex.toBits(vector["iv_hex"].replace(/\s/g,''))
  18. });
  19. equal(sjcl.codec.hex.fromBits(plaintext), vector["plaintext_hex"].replace(/\s/g,''));
  20. }