src/crypto/cryptoHelpers.js
function(data, key) {
    // Errors
    if (!data || !key) throw new Error('Missing argument !');
    // Processing
    let iv = nacl.randomBytes(16)
    let encKey = convert.ua2words(key, 32);
    let encIv = {
        iv: convert.ua2words(iv, 16)
    };
    let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Hex.parse(data), encKey, encIv);
    // Result
    return {
        ciphertext: encrypted.ciphertext,
        iv: iv,
        key: key
    };
}
function(data, key) {
    // Errors
    if (!data || !key) throw new Error('Missing argument !');
    // Processing
    let iv = nacl.randomBytes(16)
    let encKey = convert.ua2words(key, 32);
    let encIv = {
        iv: convert.ua2words(iv, 16)
    };
    let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Hex.parse(data), encKey, encIv);
    // Result
    return {
        ciphertext: encrypted.ciphertext,
        iv: iv,
        key: key
    };
}
function ( data , key ) { // Errors if ( ! data || ! key ) throw new Error ( 'Missing argument !' ) ; // Processing let iv = nacl . randomBytes ( 16 ) let encKey = convert . ua2words ( key , 32 ) ; let encIv = { iv : convert . ua2words ( iv , 16 ) } ; let encrypted = CryptoJS . AES . encrypt ( CryptoJS . enc . Hex . parse ( data ) , encKey , encIv ) ; // Result return { ciphertext : encrypted . ciphertext , iv : iv , key : key } ; }
Encrypt hex data using a key

@param {string} data - An hex string
@param {Uint8Array} key - An Uint8Array key

@return {object} - The encrypted data
Encrypt hex data using a key