Ejemplo n.º 1
0
        public SenderMessageKey(uint iteration, byte[] seed)
        {
            byte[] derivative = new HKDFv3().deriveSecrets(seed, Encoding.UTF8.GetBytes("WhisperGroup"), 48);
            byte[][] parts = ByteUtil.split(derivative, 16, 32);

            this.iteration = iteration;
            this.seed = seed;
            this.iv = parts[0];
            this.cipherKey = parts[1];
        }
        public byte[] encrypt(ProvisionMessage message)// throws InvalidKeyException
        {
            ECKeyPair ourKeyPair = Curve.generateKeyPair();
            byte[] sharedSecret = Curve.calculateAgreement(theirPublicKey, ourKeyPair.getPrivateKey());
            byte[] derivedSecret = new HKDFv3().deriveSecrets(sharedSecret, Encoding.UTF8.GetBytes("TextSecure Provisioning Message"), 64);
            byte[][] parts = Util.split(derivedSecret, 32, 32);

            byte[] version = { 0x01 };
            byte[] ciphertext = getCiphertext(parts[0], message.ToByteArray());
            byte[] mac = getMac(parts[1], Util.join(version, ciphertext));
            byte[] body = Util.join(version, ciphertext, mac);

            return ProvisionEnvelope.CreateBuilder()
                                    .SetPublicKey(ByteString.CopyFrom(ourKeyPair.getPublicKey().serialize()))
                                    .SetBody(ByteString.CopyFrom(body))
                                    .Build()
                                    .ToByteArray();
        }