lib/security/cipher.js
function aesEncrypt(msg, key, iv) {
    var logger = getLogger('security.cipher.aesEncrypt');
    // Check if padding is needed
    var padding = msg.length % 16;
    if (padding > 0) {
        var paddingBuffer = utility.createRandomBuffer(16 - padding);
        msg = Buffer.concat([msg, paddingBuffer]);
    }
    // Convert buffers to wordArrays
    var plainMsg = buffer2WordArray(msg);
    var keyWordArray = buffer2WordArray(key);
    var ivWordArray = buffer2WordArray(iv);
    if (logger.isDebugEnabled()) {
        logger.debug('plainMsg = %s\nkeyWordArray = %s\nivWordArray = %s',
            JSON.stringify(plainMsg), JSON.stringify(keyWordArray), JSON.stringify(ivWordArray));
    }
    // Encrypt plain message
    var encryptedWordArray = CryptoJS.AES.encrypt(plainMsg, keyWordArray, {
        iv: ivWordArray,
        padding: CryptoJS.pad.NoPadding,
        mode: CryptoJS.mode.IGE
    }).ciphertext;
    if (logger.isDebugEnabled()) {
        logger.debug('encryptedWordArray = %s', JSON.stringify(encryptedWordArray));
    }
    // Return the encrypted buffer
    return wordArray2Buffer(encryptedWordArray);
}
function aesEncrypt(msg, key, iv) {
    var logger = getLogger('security.cipher.aesEncrypt');
    // Check if padding is needed
    var padding = msg.length % 16;
    if (padding > 0) {
        var paddingBuffer = utility.createRandomBuffer(16 - padding);
        msg = Buffer.concat([msg, paddingBuffer]);
    }
    // Convert buffers to wordArrays
    var plainMsg = buffer2WordArray(msg);
    var keyWordArray = buffer2WordArray(key);
    var ivWordArray = buffer2WordArray(iv);
    if (logger.isDebugEnabled()) {
        logger.debug('plainMsg = %s\nkeyWordArray = %s\nivWordArray = %s',
            JSON.stringify(plainMsg), JSON.stringify(keyWordArray), JSON.stringify(ivWordArray));
    }
    // Encrypt plain message
    var encryptedWordArray = CryptoJS.AES.encrypt(plainMsg, keyWordArray, {
        iv: ivWordArray,
        padding: CryptoJS.pad.NoPadding,
        mode: CryptoJS.mode.IGE
    }).ciphertext;
    if (logger.isDebugEnabled()) {
        logger.debug('encryptedWordArray = %s', JSON.stringify(encryptedWordArray));
    }
    // Return the encrypted buffer
    return wordArray2Buffer(encryptedWordArray);
}
function aesEncrypt ( msg , key , iv ) { var logger = getLogger ( 'security.cipher.aesEncrypt' ) ; // Check if padding is needed var padding = msg . length % 16 ; if ( padding > 0 ) { var paddingBuffer = utility . createRandomBuffer ( 16 - padding ) ; msg = Buffer . concat ( [ msg , paddingBuffer ] ) ; } // Convert buffers to wordArrays var plainMsg = buffer2WordArray ( msg ) ; var keyWordArray = buffer2WordArray ( key ) ; var ivWordArray = buffer2WordArray ( iv ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'plainMsg = %s\nkeyWordArray = %s\nivWordArray = %s' , JSON . stringify ( plainMsg ) , JSON . stringify ( keyWordArray ) , JSON . stringify ( ivWordArray ) ) ; } // Encrypt plain message var encryptedWordArray = CryptoJS . AES . encrypt ( plainMsg , keyWordArray , { iv : ivWordArray , padding : CryptoJS . pad . NoPadding , mode : CryptoJS . mode . IGE } ) . ciphertext ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'encryptedWordArray = %s' , JSON . stringify ( encryptedWordArray ) ) ; } // Return the encrypted buffer return wordArray2Buffer ( encryptedWordArray ) ; }
AES encrypt function
AES encrypt function