/// <inheritdoc/> public ICryptographicKey ImportKeyPair(byte[] keyBlob, CryptographicPrivateKeyBlobType blobType = CryptographicPrivateKeyBlobType.Pkcs8RawPrivateKeyInfo) { Requires.NotNull(keyBlob, "keyBlob"); RSAParameters parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob); IPrivateKey privateKey; IPublicKey publicKey; var spec = new RSAPrivateKeySpec(new BigInteger(1, parameters.Modulus), new BigInteger(1, parameters.D)); var factory = KeyFactory.GetInstance("RSA"); privateKey = factory.GeneratePrivate(spec); var privateRsaKey = privateKey.JavaCast<IRSAPrivateKey>(); var publicKeySpec = new RSAPublicKeySpec(privateRsaKey.Modulus, new BigInteger(1, parameters.Exponent)); publicKey = factory.GeneratePublic(publicKeySpec); return new RsaCryptographicKey(publicKey, privateKey, parameters, this.algorithm); }
/// <inheritdoc/> public ICryptographicKey ImportPublicKey(byte[] keyBlob, CryptographicPublicKeyBlobType blobType = CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo) { Requires.NotNull(keyBlob, "keyBlob"); var parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob); var spec = new RSAPublicKeySpec(new BigInteger(1, parameters.Modulus), new BigInteger(1, parameters.Exponent)); KeyFactory factory = KeyFactory.GetInstance("RSA"); IPublicKey publicKey = factory.GeneratePublic(spec); return new RsaCryptographicKey(publicKey, parameters, this.algorithm); }