/// <summary> /// Creates a new <see cref="Certificate"/> from .pfx format data in memory. /// </summary> /// <param name="data">The certificate data in .pfx format.</param> /// <param name="password">The password to access the certificate private key. This can be null if the PFX is not protected by a password.</param> /// <returns>A <see cref="Certificate"/> representing a new certificate that has not been added to the Batch service.</returns> public Certificate CreateCertificateFromPfx(byte[] data, string password = null) { Models.CertificateAddParameter protoCert = GetCertificateInfo(data, password); Certificate omCert = new Certificate(this.ParentBatchClient, protoCert, this.CustomBehaviors); return(omCert); }
/// <summary> /// Creates a new <see cref="Certificate"/> from .cer format data in memory. /// </summary> /// <param name="data">The certificate data in .cer format.</param> /// <returns>A <see cref="Certificate"/> representing a new certificate that has not been added to the Batch service.</returns> public Certificate CreateCertificateFromCer(byte[] data) { Models.CertificateAddParameter protoCert = GetCertificateInfo(data); Certificate omCert = new Certificate(this.ParentBatchClient, protoCert, this.CustomBehaviors); return(omCert); }
private Models.CertificateAddParameter GetCertificateInfo(byte[] rawData) { var certificate = new X509Certificate2(rawData); Models.CertificateAddParameter cert = CreateAddCertificateEntity(rawData, certificate); cert.CertificateFormat = Models.CertificateFormat.Cer; return(cert); }
internal Certificate(BatchClient parentBatchClient, Models.CertificateAddParameter protocolObject, IEnumerable <BatchClientBehavior> baseBehaviors) : this( parentBatchClient, baseBehaviors, protocolObject.Data, protocolObject.Thumbprint, protocolObject.ThumbprintAlgorithm, UtilitiesInternal.MapNullableEnum <Models.CertificateFormat, Common.CertificateFormat>(protocolObject.CertificateFormat), protocolObject.Password) { }
private static Models.CertificateAddParameter CreateAddCertificateEntity(byte[] rawData, X509Certificate2 certificate) { Models.CertificateAddParameter cert = new Models.CertificateAddParameter(); cert.Thumbprint = certificate.Thumbprint.ToLowerInvariant(); //ThumbprintAlgorithm is always SHA1 since thumbprint is dynamically generated from the cert body cert.ThumbprintAlgorithm = KnownCertificateAlgorithm; cert.Data = Convert.ToBase64String(rawData); return(cert); }
private Models.CertificateAddParameter GetCertificateInfo(byte[] rawData, string password) { var certificate = new X509Certificate2(rawData, password); Models.CertificateAddParameter cert = CreateAddCertificateEntity(rawData, certificate); cert.Password = password; cert.CertificateFormat = Models.CertificateFormat.Pfx; return(cert); }
/// <summary> /// Creates a new <see cref="Certificate"/> from a .pfx file. /// </summary> /// <param name="path">The path to the .pfx file.</param> /// <param name="password">The password to access the certificate private key. This can be null if the PFX is not protected by a password.</param> /// <returns>A <see cref="Certificate"/> representing a new certificate that has not been added to the Batch service.</returns> public Certificate CreateCertificateFromPfx(string path, string password = null) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentOutOfRangeException(nameof(path)); } Models.CertificateAddParameter protoCert = GetCertificateInfo(path, password); Certificate omCert = new Certificate(this.ParentBatchClient, protoCert, this.CustomBehaviors); return(omCert); }
/// <summary> /// Creates a new <see cref="Certificate"/> from a .pfx file. /// </summary> /// <param name="pfxFileName">The path to the .pfx file.</param> /// <param name="password">The password to access the certificate private key.</param> /// <returns>A <see cref="Certificate"/> representing a new certificate that has not been added to the Batch service.</returns> public Certificate CreateCertificate(string pfxFileName, string password) { if (string.IsNullOrWhiteSpace(pfxFileName)) { throw new ArgumentOutOfRangeException("pfxFileName"); } Models.CertificateAddParameter protoCert = GetCertificateInfo(pfxFileName, password); Certificate omCert = new Certificate(this.ParentBatchClient, protoCert, this.CustomBehaviors); return(omCert); }
private static Models.CertificateAddParameter CreateAddCertificateEntity(byte[] rawData, X509Certificate2 certificate) { Models.CertificateAddParameter cert = new Models.CertificateAddParameter(); cert.Thumbprint = certificate.Thumbprint.ToLower(); if (certificate.SignatureAlgorithm.FriendlyName.Contains(KnownCertificateAlgorithm)) { cert.ThumbprintAlgorithm = KnownCertificateAlgorithm; } else { cert.ThumbprintAlgorithm = certificate.SignatureAlgorithm.FriendlyName; } cert.Data = Convert.ToBase64String(rawData); return(cert); }