About export pkcs12 from keychain

yuanboyuanbo USMember

When i export pkcs12 from keychain in iOS, I have 2 ways to deal with it, but there are some problems in these 2 ways.
I need your help, thank you.

one: use xamarin.ios

                string aesEncryptSN = "abc1234444"
                SecRecord sec = new SecRecord(SecKind.Key)
                {
                    ApplicationLabel = aesEncryptSN,
                };

                SecRecord result = SecKeyChain.QueryAsRecord(sec, out code);
                if (result != null)
                {
                   return result.ValueData.ToArray();

        ??????????????
            }

From this way I can successfully export pkcs12, but the password was the original password , I don't know how to use a new simple password to replace it and re-generate a PKCS12 file and export it ?

two: use .net

                string aesEncryptSN = "abc1234444"
                SecRecord sec = new SecRecord(SecKind.Key)
                {
                    ApplicationLabel = aesEncryptSN,
                };

                SecRecord result = SecKeyChain.QueryAsRecord(sec, out code);
                if (result != null)
                {
                    bytes = result.ValueData.ToArray();

                    X509Certificate2Collection col = new X509Certificate2Collection();
                    col.Import(bytes , originalPassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
                    return col.Export(X509ContentType.Pfx, newPassWord);
    }

From this way I can successfully export pkcs12 and replace the original Password use new password.
But the pkcs12 is missing certificate chains.
It's sucess in windows system when use the same way, the Pkcs12 contains certificate chains.

My project has been developed for more than 6 months, and has been successfully released. This problem has been bothering me, and I sincerely hope that you can help me.

thanks very much.

Answers

  • yuanboyuanbo USMember

    Ask every day, do you have some updates? Online, etc.

Sign In or Register to comment.