/// <inheritdoc/> public object Create(string algorithm, params object[] args) { if (IsSupportedAlgorithm(algorithm, args)) { if (algorithm.Equals("EdDSA", StringComparison.OrdinalIgnoreCase)) { var keyMaterial = args[0] as JsonWebKey; if (keyMaterial != null) { //TODO: Probably should check a case where both are defined (or some other combinations). AsymmetricKeyParameter?keyParameter = null; if (keyMaterial.X != null) { var decodedPublicBytes = Base64UrlEncoder.DecodeBytes(keyMaterial.X); keyParameter = new Ed25519PublicKeyParameters(decodedPublicBytes, 0); } else if (keyMaterial.D != null) { var decodedPrivateBytes = Base64UrlEncoder.DecodeBytes(keyMaterial.D); keyParameter = new Ed25519PrivateKeyParameters(decodedPrivateBytes, 0); } else { throw new ArgumentException("Key material needs to be provided"); } var securityKey = new BouncyCastleEdDsaSecurityKey(keyParameter, keyMaterial.Crv, this); return(new BouncyCastleEdDsaSignatureProvider(securityKey, algorithm)); } throw new ArgumentException($"The key material argument in position args[0] expected is \"{typeof(JsonWebKey)}\"."); } } throw new NotSupportedException(); }
/// <summary> /// Default constructor for this signer. /// </summary> /// <param name="key">The key material.</param> /// <param name="algorithm">The algorithm.</param> public BouncyCastleEdDsaSignatureProvider(BouncyCastleEdDsaSecurityKey key, string algorithm) : base(key, algorithm, willCreateSignatures: key.PrivateKeyStatus == PrivateKeyStatus.Exists) { EdDsaKey = key; }