How to get PKCS8 privatekey from byte stream in C#
<p>When retrieving the PKCS8 private key using below code, I get a <code>NullReferenceException</code>. </p>

<pre><code>public ECPrivateKeyParameters GetMerchantPrivateKey(byte[] privateKeyBite)
{
    Asn1Sequence seq = (Asn1Sequence)Asn1Object.FromByteArray(privateKeyBite);
    ECPrivateKeyStructure pKey = ECPrivateKeyStructure.GetInstance(seq);
    AlgorithmIdentifier algId = new AlgorithmIdentifier(X9ObjectIdentifiers.IdECPublicKey, pKey.GetParameters());

    PrivateKeyInfo privInfo = new PrivateKeyInfo(algId, pKey.ToAsn1Object());

    return (ECPrivateKeyParameters)PrivateKeyFactory.CreateKey(privInfo);
}

[Fact]
public void GetMerchantPrivateKey__ShouldReturnPrivateKey__WhenPassPrivateKeyBytes()
{
    ApplePay applePay = new ApplePay(new MOBSHOPApplePayRequest());
    byte[] privateKey = Base64.Decode("MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgjyo3fzxT7j+CFxC7I4B5iVee2FUyn2vfOSjcgp2/g6qhRANCAARdoBFEtnuapXFKw4DYWsW0yV4bavpdWKszkefi19AhlIRE3WSNWSn25W5tZNFjMWtLISBmqANyufx2xP19oRvy");
    applePay.GetMerchantPrivateKey(privateKey);
}
</code></pre>

<p>The stack trace</p>

<pre><code>Object reference not set to an instance of an object.
BouncyCastle.Crypto
at Org.BouncyCastle.Security.PrivateKeyFactory.CreateKey(PrivateKeyInfo keyInfo)
</code></pre>

<p>If I use <code>X9ObjectIdentifiers.IdDsa</code> I get this error</p>

<pre><code>Unable to cast object of type 'Org.BouncyCastle.Asn1.DerSequence' to type 'Org.BouncyCastle.Asn1.DerInteger'.
</code></pre>

<p>This Java example does work:</p>

<pre><code>private PrivateKey inflatePrivateKey() throws Exception {
        KeyFactory keyFactory = KeyFactory.getInstance( "EC" );
        return keyFactory.generatePrivate( new PKCS8EncodedKeySpec( _dataProvider.getPrivateKeyBytes() ) );
    }
</code></pre>

<p>Please check it and help me out in C#</p>