将JAVA代码KeyStore.getInstance转换为c#

将JAVA代码KeyStore.getInstance转换为c#,java,c#,pkcs#12,Java,C#,Pkcs#12,我正在尝试将下面的JAVA代码转换为C以获取ECPrivateKey private static ECPrivateKey loadPrivateKey(String pkcs12Filename) throws KeyStoreException, NoSuchProviderException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException { KeySt

我正在尝试将下面的
JAVA
代码转换为
C
以获取
ECPrivateKey

private static ECPrivateKey loadPrivateKey(String pkcs12Filename) throws KeyStoreException, NoSuchProviderException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException {
    KeyStore keystore = KeyStore.getInstance("PKCS12", "BC");
    keystore.load(new FileInputStream(pkcs12Filename), "".toCharArray());
    assert keystore.size() == 1 : "wrong number of entries in keychain";
    Enumeration<String> aliases = keystore.aliases();
    String alias = null;
    while (aliases.hasMoreElements()) {
      alias = aliases.nextElement();
    }
    return (ECPrivateKey) keystore.getKey(alias, null);
}
private static ECPrivateKey loadPrivateKey(字符串pkcs12Filename)抛出KeyStoreException、NoSuchProviderException、IOException、NoSuchAlgorithmException、certificateeException、UnrecoverableKeyException{
KeyStore KeyStore=KeyStore.getInstance(“PKCS12”、“BC”);
load(新文件输入流(pkcs12Filename),“”.tocharray());
assert keystore.size()==1:“keychain中的条目数错误”;
枚举别名=keystore.alias();
字符串别名=null;
while(别名.hasMoreElements()){
别名=别名.nextElement();
}
return(ECPrivateKey)keystore.getKey(别名,null);
}

这是代码,我用它得到了输出

private void GetPrivateKeyFromP12(string path, string passWord)
        {
            //this.mKeyStoreEntities = PKCSUtils.extractEntities(privateKeyFilePath, privateKeyPassword);
            /**
             * Java has a minimum requirement for keystore password lengths.  Utilities like KeyChain will
             * allow you to specify less but then you will receive an obscure java error when trying to
             * load the keystore.  Check for it here and throw a meaningful error
             */

            //X509Certificate certificate;
            //ECPrivateKey privateKey;

            using (StreamReader reader = new StreamReader(path))
            {
                var fs = reader.BaseStream;
                GetMerchantIdentifierField(fs);

                fs.Position = 0;
                GetPrivateKey(fs, passWord);
            }
        }

        private void GetPrivateKey(Stream fs, string passWord)
        {
            Pkcs12Store store = new Pkcs12Store(fs, passWord.ToCharArray());

            foreach (string n in store.Aliases)
            {
                if (store.IsKeyEntry(n))
                {
                    AsymmetricKeyEntry asymmetricKey = store.GetKey(n);

                    if (asymmetricKey.Key.IsPrivate)
                    {
                        this.merchantPrivateKey = asymmetricKey.Key as ECPrivateKeyParameters;
                    }
                }
            }
        }

嗨,raju,这段代码中的GetMerchantIdentifier字段是什么?