Microsoft.Azure.Commands.RecoveryServices.CertUtils.NewX509Certificate2 C# (CSharp) Method

NewX509Certificate2() public static method

Provides a similar API call to new X509Certificate(byte[],string,X509KeyStorageFlags)
public static NewX509Certificate2 ( byte rawData, string password, X509KeyStorageFlags keyStorageFlags, bool shouldValidatePfx ) : X509Certificate2
rawData byte The bytes that represent the certificate
password string The certificate private password
keyStorageFlags X509KeyStorageFlags The certificate loading options
shouldValidatePfx bool Flag to indicate if file should validated. Set to true if the rawData is retrieved from an untrusted source.
return System.Security.Cryptography.X509Certificates.X509Certificate2
        public static X509Certificate2 NewX509Certificate2(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags, bool shouldValidatePfx)
        {
            string temporaryFileName = Path.GetTempFileName();

            try
            {
                X509ContentType contentType = X509Certificate2.GetCertContentType(rawData);
                File.WriteAllBytes(temporaryFileName, rawData);
                return new X509Certificate2(temporaryFileName, password, keyStorageFlags);
            }
            finally
            {
                try
                {
                    File.Delete(temporaryFileName);
                }
                catch (Exception)
                {
                    // Not deleting the file is fine
                }
            }
        }