jwkFromCryptoKeyPair method
JsonWebKey?
jwkFromCryptoKeyPair(
- 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
});
}