KeyPair.fresh constructor

KeyPair.fresh()

Creates a fresh private and public key for ECDH with 512 bits from a secure random algorithm.

Implementation

KeyPair.fresh() {
  BigInt secret = randomBigInt(512);

  EllipticCurvePoint publicKeyPoint =
      M511.multiply(M511.secureBasePoint, secret);

  privateKeyHex = secret.toRadixString(16);
  publicKeyHex =
      "${publicKeyPoint.x.toRadixString(16)}/${publicKeyPoint.y.toRadixString(16)}";
}