本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Certificate2.Import方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2.Import方法的具体用法?C# X509Certificate2.Import怎么用?C# X509Certificate2.Import使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.X509Certificates.X509Certificate2
的用法示例。
在下文中一共展示了X509Certificate2.Import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCertData
public static string GetCertData(string pfxPath, string password)
{
if (!string.IsNullOrEmpty(pfxPath))
{
var cert = new X509Certificate2();
cert.Import(pfxPath, password, X509KeyStorageFlags.Exportable);
return cert.HasPrivateKey
? Convert.ToBase64String(cert.Export(X509ContentType.Pfx, password))
: Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12));
}
return null;
}
示例2: GetSecurityToken
/// <summary>
/// This method is used to create the security token from certificate from pfx file
/// </summary>
internal static X509SecurityToken GetSecurityToken()
{
X509Certificate2 certificateToBeAdded = new X509Certificate2();
string certificateFile = ConfigurationManager.AppSettings["PfxCertificateFile"];
certificateToBeAdded.Import(certificateFile, "", X509KeyStorageFlags.MachineKeySet);
return new X509SecurityToken(certificateToBeAdded);
}
示例3: deserialize
public static X509Certificate2 deserialize(string rawData)
{
var raw = Convert.FromBase64String(rawData);
var cert = new X509Certificate2();
cert.Import(raw);
return cert;
}
示例4: GetCertFromPfxFile
private static X509Certificate2 GetCertFromPfxFile(string path, SecureString password)
{
X509Certificate2 x509Certificate2 = new X509Certificate2();
string stringFromSecureString = SecurityUtils.GetStringFromSecureString(password);
x509Certificate2.Import(path, stringFromSecureString, X509KeyStorageFlags.DefaultKeySet);
return x509Certificate2;
}
示例5: RSACryptography
/// <summary>
/// Create new RSACryptography from byte array
/// </summary>
/// <param name="certificated"></param>
public RSACryptography(byte[] certificated)
{
if (certificated == null)
throw new CryptographicException("Thông tư chứng thư cần khác empty và null.");
cert = new X509Certificate2();
cert.Import(certificated);
ValidateCert();
}
示例6: Create
public static X509Certificate2 Create(ushort keyLength, DateTime start, DateTime end)
{
byte[] rawData = CreatePfxWithSelfSignedCertificate(keyLength, start, end);
X509Certificate2 certToReturn = new X509Certificate2();
certToReturn.Import(rawData);
return certToReturn;
}
示例7: GetCertificate
public static X509Certificate2 GetCertificate(string publishSettings)
{
XmlDocument xmlPublicSetting = new XmlDocument();
xmlPublicSetting.LoadXml(publishSettings);
X509Certificate2 cert = new X509Certificate2();
XmlNode publishProfile = xmlPublicSetting.SelectSingleNode("/PublishData/PublishProfile");
string certificateString = publishProfile.Attributes["ManagementCertificate"].Value;
cert.Import(Convert.FromBase64String(certificateString));
return cert;
}
示例8: GetX5092
public X509Certificate2 GetX5092()
{
X509Certificate2 xc = new X509Certificate2();
try
{
byte[] x509 = Read();
xc.Import(x509, "", X509KeyStorageFlags.DefaultKeySet);
}
catch { }
return xc;
}
示例9: MerrNenshkrimInfo
private Nenshkrim MerrNenshkrimInfo(AcroFields af, string name)
{
PdfPKCS7 pkcs7 = af.VerifySignature(name);
var certificate = new X509Certificate2();
var cert = (Org.BouncyCastle.X509.X509Certificate)pkcs7.Certificates[0];
certificate.Import(cert.GetEncoded());
Nenshkrim nenshkruesi = new Nenshkrim();
nenshkruesi.Nenshkruesi = CertificateInfo.GetSubjectFields(cert).GetField("CN");
string issuer = certificate.Issuer;
nenshkruesi.IssuerCN = GetIssuer(issuer, "CN=");
nenshkruesi.IssuerOU = GetIssuer(issuer, "OU=");
nenshkruesi.IssuerO = GetIssuer(issuer, "O=");
nenshkruesi.IssuerC = GetIssuer(issuer, "C=");
if (nenshkruesi.IssuerC == "KS")
{
//largimi i [EMAIL] prej cn
nenshkruesi.Nenshkruesi = nenshkruesi.Nenshkruesi.Substring(8);
}
nenshkruesi.Emri = CertificateInfo.GetSubjectFields(cert).GetField("GIVENNAME");
nenshkruesi.Mbiemri = CertificateInfo.GetSubjectFields(cert).GetField("SURNAME");
//algoritmi hash
nenshkruesi.AlgoritmiHash = pkcs7.GetHashAlgorithm();
//algoritmi hash
nenshkruesi.AlgoritmiEnkriptimit = pkcs7.GetEncryptionAlgorithm();
//data e nenshrimit
nenshkruesi.DataNenshkrimit = pkcs7.SignDate;
//certifikata valide prej, deri
nenshkruesi.CertifikataValidePrej = certificate.GetEffectiveDateString();
nenshkruesi.CertifikataValideDeri = certificate.GetExpirationDateString();
nenshkruesi.SerialNumber = certificate.SerialNumber;
//verifikimi
if (pkcs7.Verify())
{
nenshkruesi.Valid = true;
}
else
{
nenshkruesi.Valid = false;
}
return nenshkruesi;
}
示例10: AwakeFromNib
public override void AwakeFromNib ()
{
base.AwakeFromNib ();
SolutionUserDto = SolutionUserDtoOriginal.DeepCopy();
TxtName.StringValue = SolutionUserDto.Name;
TxtDescription.StringValue = string.IsNullOrEmpty(SolutionUserDto.Description)?string.Empty:SolutionUserDto.Description;
CbDisabled.StringValue = SolutionUserDto.Disabled ? "1" : "0";
Window.Title = SolutionUserDto.Name + " Properties";
var cert = new X509Certificate2 (Encoding.ASCII.GetBytes(SolutionUserDto.Certificate.Encoded));
try {
TxtIssuer.StringValue = cert.Issuer;
TxtValidFrom.StringValue = cert.NotBefore.ToShortDateString();
TxtValidTo.StringValue = cert.NotAfter.ToShortDateString();
TxtDC.StringValue = cert.IssuerName.Format(true);
} catch (Exception) {
UtilityService.ShowAlert ("Invalid X509 certificate", "Alert");
}
//Events
this.BtnSave.Activated += OnClickSaveButton;
this.BtnClose.Activated += (object sender, EventArgs e) => {
this.Close ();
NSApplication.SharedApplication.StopModalWithCode (0);
};
this.BtnChangeCertificate.Activated += (object sender, EventArgs e) => {
var openPanel = new NSOpenPanel();
openPanel.ReleasedWhenClosed = true;
openPanel.Prompt = "Select file";
var result = openPanel.RunModal();
if (result == 1)
{
var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty);
var cert1 = new X509Certificate2 ();
try {
cert1.Import (filePath);
TxtIssuer.StringValue = cert1.Issuer;
TxtValidFrom.StringValue = cert1.NotBefore.ToShortDateString();
TxtValidTo.StringValue = cert1.NotAfter.ToShortDateString();
TxtDC.StringValue = cert1.IssuerName.Format(true);
} catch (Exception) {
UtilityService.ShowAlert ("Invalid X509 certificate", "Alert");
}
SolutionUserDto.Certificate.Encoded = cert.ToPem();
}
};
}
示例11: RequestInvoker
public RequestInvoker(string publishSettings)
{
XmlDocument xmlPublicSetting = new XmlDocument();
xmlPublicSetting.LoadXml(publishSettings);
X509Certificate2 cert = new X509Certificate2();
XmlNode publishProfile = xmlPublicSetting.SelectSingleNode("/PublishData/PublishProfile");
string certificateString = publishProfile.Attributes["ManagementCertificate"].Value;
cert.Import(Convert.FromBase64String(certificateString));
this.Certificate = cert;
XmlNode subscriptionNode = xmlPublicSetting.SelectSingleNode("/PublishData/PublishProfile/Subscription");
this.SubscriptionId = subscriptionNode.Attributes["Id"].Value;
this.SubscriptionName = subscriptionNode.Attributes["Name"].Value;
}
示例12: IsResponseValid
public bool IsResponseValid(XmlDocument xDoc)
{
XmlNamespaceManager manager = new XmlNamespaceManager(xDoc.NameTable);
manager.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);
XmlNodeList nodeList = xDoc.SelectNodes("//ds:Signature", manager);
SignedXml signedXml = new SignedXml(xDoc);
signedXml.LoadXml((XmlElement)nodeList[0]);
X509Certificate2 cSigningCertificate = new X509Certificate2();
cSigningCertificate.Import(HttpContext.Current.Server.MapPath(".") + @"\Certificates\SignCertFromCentrify.cer");
return signedXml.CheckSignature(cSigningCertificate, true);
}
示例13: ObtieneCertificadoDesdeArchivo
private X509Certificate2 ObtieneCertificadoDesdeArchivo( string argArchivo )
{
X509Certificate2 objCert = new X509Certificate2();
try
{
objCert.Import( this.accesoDisco.ObtenerBytes( argArchivo ) );
}
catch ( Exception error )
{
this.manejadorErrores.ManejarError( error, "ObtieneCertificadoDesdeArchivo", error.Message );
}
return objCert;
}
示例14: ObtieneCertificadoDesdeArchivo
/// <summary>
/// Lee certificado de disco
/// </summary>
/// <param name="argArchivo">Ruta del certificado a leer.</param>
/// <returns>Un objeto certificado X509</returns>
/// <remarks></remarks>
public static X509Certificate2 ObtieneCertificadoDesdeArchivo(string argArchivo, string key)
{
X509Certificate2 objCert = new X509Certificate2();
try
{
objCert.Import(Microsoft.VisualBasic.FileIO.FileSystem.ReadAllBytes(argArchivo), key, X509KeyStorageFlags.DefaultKeySet);
return objCert;
}
catch (Exception excepcionAlImportarCertificado)
{
throw new Exception("argArchivo=" + argArchivo + " excepcion=" + excepcionAlImportarCertificado.Message + " " + excepcionAlImportarCertificado.StackTrace);
}
}
示例15: InstallPfx
public static void InstallPfx(string filePath, string password, string[] privateKeyUsers)
{
Console.WriteLine(string.Format("Installing certificate using file: [{0}].", filePath));
var cert = new X509Certificate2();
cert.Import(filePath, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet );
if (cert.HasPrivateKey)
{
GrantUserReadAccessToCertificate(privateKeyUsers, cert);
}
AddCertToStore(cert);
RemoveCertFileFromDisk(filePath);
}