Search in sources :

Example 6 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by WhisperSystems.

the class AsymmetricMasterCipher method encryptBytes.

public byte[] encryptBytes(byte[] body) {
    try {
        ECPublicKey theirPublic = asymmetricMasterSecret.getDjbPublicKey();
        ECKeyPair ourKeyPair = Curve.generateKeyPair();
        byte[] secret = Curve.calculateAgreement(theirPublic, ourKeyPair.getPrivateKey());
        MasterCipher masterCipher = getMasterCipherForSecret(secret);
        byte[] encryptedBodyBytes = masterCipher.encryptBytes(body);
        PublicKey ourPublicKey = new PublicKey(31337, ourKeyPair.getPublicKey());
        byte[] publicKeyBytes = ourPublicKey.serialize();
        return Util.combine(publicKeyBytes, encryptedBodyBytes);
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
Also used : ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException)

Aggregations

ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)6 TextSecurePreKeyStore (org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore)3 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)3 SignedPreKeyStore (org.whispersystems.libsignal.state.SignedPreKeyStore)3 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)2 PreKeyStore (org.whispersystems.libsignal.state.PreKeyStore)2 LinkedList (java.util.LinkedList)1 IdentityKey (org.whispersystems.libsignal.IdentityKey)1 InvalidKeyIdException (org.whispersystems.libsignal.InvalidKeyIdException)1 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)1 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)1