src/crypto/crypto.js
function(password, privateKey) {
    // Errors
    if (!password || !privateKey) throw new Error('Missing argument !');
    //if (!Helpers.isPrivateKeyValid(privateKey)) throw new Error('Private key is not valid !');
    // Processing
    let salt = CryptoJS.lib.WordArray.random(256 / 8);
    let key = CryptoJS.PBKDF2(password, salt, {
        keySize: 256 / 32,
        iterations: 2000
    });
    let iv = nacl.randomBytes(16)
    let encIv = {
        iv: ua2words(iv, 16)
    };
    let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Hex.parse(privateKey), key, encIv);
    // Result
    return {
        encrypted: convert.uint8ToHex(iv) + encrypted.ciphertext,
        salt:  salt.toString()
    }
}
function(password, privateKey) {
    // Errors
    if (!password || !privateKey) throw new Error('Missing argument !');
    //if (!Helpers.isPrivateKeyValid(privateKey)) throw new Error('Private key is not valid !');
    // Processing
    let salt = CryptoJS.lib.WordArray.random(256 / 8);
    let key = CryptoJS.PBKDF2(password, salt, {
        keySize: 256 / 32,
        iterations: 2000
    });
    let iv = nacl.randomBytes(16)
    let encIv = {
        iv: ua2words(iv, 16)
    };
    let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Hex.parse(privateKey), key, encIv);
    // Result
    return {
        encrypted: convert.uint8ToHex(iv) + encrypted.ciphertext,
        salt:  salt.toString()
    }
}
function ( password , privateKey ) { // Errors if ( ! password || ! privateKey ) throw new Error ( 'Missing argument !' ) ; //if (!Helpers.isPrivateKeyValid(privateKey)) throw new Error('Private key is not valid !'); // Processing let salt = CryptoJS . lib . WordArray . random ( 256 / 8 ) ; let key = CryptoJS . PBKDF2 ( password , salt , { keySize : 256 / 32 , iterations : 2000 } ) ; let iv = nacl . randomBytes ( 16 ) let encIv = { iv : ua2words ( iv , 16 ) } ; let encrypted = CryptoJS . AES . encrypt ( CryptoJS . enc . Hex . parse ( privateKey ) , key , encIv ) ; // Result return { encrypted : convert . uint8ToHex ( iv ) + encrypted . ciphertext , salt : salt . toString ( ) } }
Encrypt a private key for mobile apps (AES_PBKF2)

@param {string} password - A wallet password
@param {string} privateKey - An account private key

@return {object} - The encrypted data
Encrypt a private key for mobile apps ( AES_PBKF2 )