Org.BouncyCastle.OpenSsl.PemReader.ReadECPrivateKey C# (CSharp) Method

ReadECPrivateKey() private method

private ReadECPrivateKey ( string endMarker ) : AsymmetricCipherKeyPair
endMarker string
return Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair
		private AsymmetricCipherKeyPair ReadECPrivateKey(
			string endMarker)
		{
			try
			{
				byte[] bytes = ReadBytes(endMarker);
				ECPrivateKeyStructure pKey = new ECPrivateKeyStructure(
					(Asn1Sequence) Asn1Object.FromByteArray(bytes));
				AlgorithmIdentifier algId = new AlgorithmIdentifier(
					X9ObjectIdentifiers.IdECPublicKey, pKey.GetParameters());

				PrivateKeyInfo privInfo = new PrivateKeyInfo(algId, pKey.ToAsn1Object());
				SubjectPublicKeyInfo pubInfo = new SubjectPublicKeyInfo(algId, pKey.GetPublicKey().GetBytes());

				// TODO Are the keys returned here ECDSA, as Java version forces?
				return new AsymmetricCipherKeyPair(
					PublicKeyFactory.CreateKey(pubInfo),
					PrivateKeyFactory.CreateKey(privInfo));
			}
			catch (InvalidCastException e)
			{ 
				throw new IOException("wrong ASN.1 object found in stream.", e);
			}
			catch (Exception e)
			{
				throw new PemException("problem parsing EC private key.", e);
			}
		}
	}