All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.whispersystems.libsignal.IdentityKeyPair Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
/**
 * Copyright (C) 2014-2016 Open Whisper Systems
 *
 * Licensed according to the LICENSE file in this repository.
 */
package org.whispersystems.libsignal;

import org.signal.client.internal.Native;

import org.whispersystems.libsignal.ecc.ECPrivateKey;

/**
 * Holder for public and private identity key pair.
 *
 * @author Moxie Marlinspike
 */
public class IdentityKeyPair {
  private final IdentityKey  publicKey;
  private final ECPrivateKey privateKey;

  public IdentityKeyPair(IdentityKey publicKey, ECPrivateKey privateKey) {
    this.publicKey  = publicKey;
    this.privateKey = privateKey;
  }

  public IdentityKeyPair(byte[] serialized) {
    long[] tuple = Native.IdentityKeyPair_Deserialize(serialized);
    long publicKeyHandle = tuple[0];
    long privateKeyHandle = tuple[1];

    this.publicKey = new IdentityKey(publicKeyHandle);
    this.privateKey = new ECPrivateKey(privateKeyHandle);
  }

  public IdentityKey getPublicKey() {
    return publicKey;
  }

  public ECPrivateKey getPrivateKey() {
    return privateKey;
  }

  public byte[] serialize() {
    return Native.IdentityKeyPair_Serialize(this.publicKey.nativeHandle(), this.privateKey.nativeHandle());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy