encryption.spec.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Import modules. */
  2. const Nito = require('../..')
  3. describe('Crypto:encryption', () => {
  4. test('it should verify that ciphertext is unique for the same plaintext', async () => {
  5. /* Initialize public key. */
  6. // NOTE: Address is bitcoincash:qppv9s692qudqk4x3etsndhsu3fuuvvdqvklhyn7jj
  7. const pubKey = '02316e0085ee32e2b949eb03fdd40bc6fd57bf46b4d9b1ed2ed90bba0291ad7ea4'
  8. /* Initialize plaintext message. */
  9. const plaintext = 'Chancellor on brink of second bailout for banks'
  10. /* Generate random bytes. */
  11. const ciphertext = Nito.Crypto.Encryption.encrypt(plaintext, pubKey)
  12. /* Generate random bytes. */
  13. const ciphertext_verify = Nito.Crypto.Encryption.encrypt(plaintext, pubKey)
  14. /* Evaluate test. */
  15. expect(ciphertext).not.toEqual(ciphertext_verify)
  16. })
  17. test('it should verify that ciphertext can be decrypted', async () => {
  18. /* Initialize WIF. */
  19. // NOTE: Address is bitcoincash:qppv9s692qudqk4x3etsndhsu3fuuvvdqvklhyn7jj
  20. const wif = 'KzBAnwuor1KaVu192x26R2FVucQbrNGVVYi5tVgKVSHHnT4WGXSv'
  21. /* Initialize ciphertext. */
  22. const ciphertext = 'QklFMQJO98eqhDMm9M1SwgGXxeXH8Fg8VYdXAm8lFngIxltZNhUJ0WD0PYyYmFR8tAooHuN/bPF1pk4JnFgvTb4FmwAS6u8+hdfbRmCiZ9nAgigLElVgtc7U+7k8Ohx3ix2iCfFcF5EJewArzErlzD53k2qk'
  23. /* Initialize expected text. */
  24. const expected = 'Chancellor on brink of second bailout for banks'
  25. /* Decrypt ciphertext. */
  26. // NOTE: Returns a buffer object.
  27. const plaintext = Nito.Crypto.Encryption.decrypt(ciphertext, wif)
  28. /* Evaluate test. */
  29. expect(plaintext.toString()).toEqual(expected)
  30. })
  31. })