src/crypto/crypto.js
function(senderPriv, recipientPub, msg, iv, salt) {
    // Errors
    if (!senderPriv || !recipientPub || !msg || !iv || !salt) throw new Error('Missing argument !');
    // Processing
    let keyPair = createKeyPairFromPrivateKeyString(senderPriv);
    let pk = convert.hexToUint8(recipientPub);
    let encKey = deriveSharedKey(keyPair, pk, salt);
    let encIv = {
        iv: ua2words(iv, 16)
    };
    let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Hex.parse(convert.utf8ToHex(msg)), encKey, encIv);
    // Result
    let result = convert.uint8ToHex(salt) + convert.uint8ToHex(iv) + CryptoJS.enc.Hex.stringify(encrypted.ciphertext);
    return result;
}
function(senderPriv, recipientPub, msg, iv, salt) {
    // Errors
    if (!senderPriv || !recipientPub || !msg || !iv || !salt) throw new Error('Missing argument !');
    // Processing
    let keyPair = createKeyPairFromPrivateKeyString(senderPriv);
    let pk = convert.hexToUint8(recipientPub);
    let encKey = deriveSharedKey(keyPair, pk, salt);
    let encIv = {
        iv: ua2words(iv, 16)
    };
    let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Hex.parse(convert.utf8ToHex(msg)), encKey, encIv);
    // Result
    let result = convert.uint8ToHex(salt) + convert.uint8ToHex(iv) + CryptoJS.enc.Hex.stringify(encrypted.ciphertext);
    return result;
}
function ( senderPriv , recipientPub , msg , iv , salt ) { // Errors if ( ! senderPriv || ! recipientPub || ! msg || ! iv || ! salt ) throw new Error ( 'Missing argument !' ) ; // Processing let keyPair = createKeyPairFromPrivateKeyString ( senderPriv ) ; let pk = convert . hexToUint8 ( recipientPub ) ; let encKey = deriveSharedKey ( keyPair , pk , salt ) ; let encIv = { iv : ua2words ( iv , 16 ) } ; let encrypted = CryptoJS . AES . encrypt ( CryptoJS . enc . Hex . parse ( convert . utf8ToHex ( msg ) ) , encKey , encIv ) ; // Result let result = convert . uint8ToHex ( salt ) + convert . uint8ToHex ( iv ) + CryptoJS . enc . Hex . stringify ( encrypted . ciphertext ) ; return result ; }
*
Encode a message, separated from encode() to help testing

@param {string} senderPriv - A sender private key
@param {string} recipientPub - A recipient public key
@param {string} msg - A text message
@param {Uint8Array} iv - An initialization vector
@param {Uint8Array} salt - A salt

@return {string} - The encoded message
* Encode a message separated from encode () to help testing