jwkFromCryptoKeyPair method

  1. @visibleForTesting
JsonWebKey jwkFromCryptoKeyPair(
  1. KeyPair keyPair
)

Implementation

@visibleForTesting
JsonWebKey jwkFromCryptoKeyPair(KeyPair keyPair) {
  return JsonWebKey.fromJson({
    'kty': type,
    if (type == 'oct')
      'k': encodeBase64EncodedBytes(
          (keyPair.publicKey as SymmetricKey).keyValue),
    if (type == 'RSA') ...{
      'n': encodeBigInt((keyPair.publicKey as RsaPublicKey).modulus),
      'e': encodeBigInt((keyPair.publicKey as RsaPublicKey).exponent),
      'd':
          encodeBigInt((keyPair.privateKey as RsaPrivateKey).privateExponent),
      'p': encodeBigInt(
          (keyPair.privateKey as RsaPrivateKey).firstPrimeFactor),
      'q': encodeBigInt(
          (keyPair.privateKey as RsaPrivateKey).secondPrimeFactor),
    },
    if (type == 'EC') ...{
      'd': encodeBigInt((keyPair.privateKey as EcPrivateKey).eccPrivateKey),
      'x': encodeBigInt((keyPair.publicKey as EcPublicKey).xCoordinate),
      'y': encodeBigInt((keyPair.publicKey as EcPublicKey).yCoordinate),
      'crv': curve,
    },
    'alg': name,
    'use': use,
    'keyOperations': keyOperations
  });
}