src/crypto.js
function(message, signaling_key) {
        if (signaling_key.byteLength != 52) {
            throw new Error("Got invalid length signaling_key");
        }
        if (message.byteLength < 1 + 16 + 10) {
            throw new Error("Got invalid length message");
        }
        if (message[0] != 1) {
            throw new Error("Got bad version number: " + message[0]);
        }
        var aes_key = signaling_key.slice(0, 32);
        var mac_key = signaling_key.slice(32, 32 + 20);
        var iv = message.slice(1, 17);
        var ciphertext = message.slice(1 + 16, message.byteLength - 10);
        var ivAndCiphertext = message.slice(0, message.byteLength - 10);
        var mac = message.slice(message.byteLength - 10, message.byteLength);
        libsignal.crypto.verifyMAC(ivAndCiphertext, mac_key, mac, 10);
        return libsignal.crypto.decrypt(aes_key, ciphertext, iv);
    }
function(message, signaling_key) {
        if (signaling_key.byteLength != 52) {
            throw new Error("Got invalid length signaling_key");
        }
        if (message.byteLength < 1 + 16 + 10) {
            throw new Error("Got invalid length message");
        }
        if (message[0] != 1) {
            throw new Error("Got bad version number: " + message[0]);
        }
        var aes_key = signaling_key.slice(0, 32);
        var mac_key = signaling_key.slice(32, 32 + 20);
        var iv = message.slice(1, 17);
        var ciphertext = message.slice(1 + 16, message.byteLength - 10);
        var ivAndCiphertext = message.slice(0, message.byteLength - 10);
        var mac = message.slice(message.byteLength - 10, message.byteLength);
        libsignal.crypto.verifyMAC(ivAndCiphertext, mac_key, mac, 10);
        return libsignal.crypto.decrypt(aes_key, ciphertext, iv);
    }
function ( message , signaling_key ) { if ( signaling_key . byteLength != 52 ) { throw new Error ( "Got invalid length signaling_key" ) ; } if ( message . byteLength < 1 + 16 + 10 ) { throw new Error ( "Got invalid length message" ) ; } if ( message [ 0 ] != 1 ) { throw new Error ( "Got bad version number: " + message [ 0 ] ) ; } var aes_key = signaling_key . slice ( 0 , 32 ) ; var mac_key = signaling_key . slice ( 32 , 32 + 20 ) ; var iv = message . slice ( 1 , 17 ) ; var ciphertext = message . slice ( 1 + 16 , message . byteLength - 10 ) ; var ivAndCiphertext = message . slice ( 0 , message . byteLength - 10 ) ; var mac = message . slice ( message . byteLength - 10 , message . byteLength ) ; libsignal . crypto . verifyMAC ( ivAndCiphertext , mac_key , mac , 10 ) ; return libsignal . crypto . decrypt ( aes_key , ciphertext , iv ) ; }
Decrypts message into a raw string
Decrypts message into a raw string