本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Certificate2.GetRawCertData方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2.GetRawCertData方法的具体用法?C# X509Certificate2.GetRawCertData怎么用?C# X509Certificate2.GetRawCertData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.X509Certificates.X509Certificate2
的用法示例。
在下文中一共展示了X509Certificate2.GetRawCertData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayCertificate
public static void DisplayCertificate (X509Certificate2 certificate, IntPtr hwndParent)
{
if (certificate == null)
throw new ArgumentNullException ("certificate");
/*byte[] raw = */ certificate.GetRawCertData ();
throw new NotImplementedException ();
}
示例2: GetXadesInfo
public static XadesInfo GetXadesInfo(X509Certificate2 certificate)
{
XadesInfo xadesInfo = new XadesInfo();
xadesInfo.RawPK = Convert.ToBase64String(certificate.GetRawCertData());
xadesInfo.SigningDateTimeUTC = DateTime.UtcNow;
TimeSpan delta = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
xadesInfo.TimeZoneOffsetMinutes = Convert.ToInt32(delta.TotalMinutes);
return xadesInfo;
}
示例3: CreateCertificate
private CertificateSet CreateCertificate()
{
//TODO: randomize the password
string password = "gb_Password1";
CertificateSet certificateSet = new CertificateSet
{
Password = password,
PfxRawData =
Certificate.CreateSelfSignCertificatePfx("O=tnLabs1,CN=tnLabs,SN=tnLabs3",
DateTime.Now.AddDays(-1), DateTime.Now.AddYears(10), password)
};
//CN is showed in the Azure Management
X509Certificate2 cert = new X509Certificate2(certificateSet.PfxRawData, password);
certificateSet.CerRawData = cert.GetRawCertData();
return certificateSet;
}
示例4: ProcessRecord
protected override void ProcessRecord()
{
if (!System.IO.Path.IsPathRooted(CertPath))
{
CertPath = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, CertPath);
}
var cert = new X509Certificate2(CertPath);
var rawCert = cert.GetRawCertData();
var base64Cert = Convert.ToBase64String(rawCert);
var rawCertHash = cert.GetCertHash();
var base64CertHash = Convert.ToBase64String(rawCertHash);
var keyId = Guid.NewGuid().ToString();
var output = string.Format("\"keyCredentials\": [\n\t{{\n\t\t\"customKeyIdentifier\": \"{0}\",\n\t\t\"keyId\": \"{1}\",\n\t\t\"type\": \"AsymmetricX509Cert\",\n\t\t\"usage\": \"Verify\",\n\t\t\"value\": \"{2}\"\n\t}}\n],", base64CertHash, keyId, base64Cert);
WriteObject(output);
}
示例5: GetSignedRequestXades
public static string GetSignedRequestXades(string request, X509Certificate2 certificate, string privateKeyPassword)
{
var originalDoc = new XmlDocument() { PreserveWhitespace = _PRESERVE_WHITESPACE };
originalDoc.LoadXml(request);
var signatureid = String.Format("xmldsig-{0}", Guid.NewGuid().ToString().ToLower());
var signedXml = GetXadesSignedXml(certificate, originalDoc, signatureid, privateKeyPassword);
var keyInfo = GetKeyInfo(Convert.ToBase64String(certificate.GetRawCertData()));
signedXml.KeyInfo = keyInfo;
var xadesInfo = GetXadesInfo(certificate);
var xadesObject = GetXadesObject(xadesInfo, signatureid);
signedXml.AddXadesObject(xadesObject);
signedXml.ComputeSignature();
InjectSignatureToOriginalDoc(signedXml, originalDoc);
return originalDoc.OuterXml;
}
示例6: AddCertificate
/// <summary>
/// Inserta en la lista de certificados el certificado y comprueba la valided del certificado.
/// </summary>
/// <param name="cert"></param>
/// <param name="unsignedProperties"></param>
/// <param name="addCertValue"></param>
/// <param name="extraCerts"></param>
private void AddCertificate(X509Certificate2 cert, UnsignedProperties unsignedProperties, bool addCert, X509Certificate2[] extraCerts = null)
{
if (addCert)
{
if (CertificateChecked(cert, unsignedProperties))
{
return;
}
string guidCert = Guid.NewGuid().ToString();
Cert chainCert = new Cert();
chainCert.IssuerSerial.X509IssuerName = cert.IssuerName.Name;
chainCert.IssuerSerial.X509SerialNumber = CertUtil.HexToDecimal(cert.SerialNumber);
DigestUtil.SetCertDigest(cert.GetRawCertData(), _firma.RefsDigestMethod, chainCert.CertDigest);
chainCert.URI = "#Cert" + guidCert;
unsignedProperties.UnsignedSignatureProperties.CompleteCertificateRefs.CertRefs.CertCollection.Add(chainCert);
EncapsulatedX509Certificate encapsulatedX509Certificate = new EncapsulatedX509Certificate();
encapsulatedX509Certificate.Id = "Cert" + guidCert;
encapsulatedX509Certificate.PkiData = cert.GetRawCertData();
unsignedProperties.UnsignedSignatureProperties.CertificateValues.EncapsulatedX509CertificateCollection.Add(encapsulatedX509Certificate);
}
var chain = CertUtil.GetCertChain(cert, extraCerts).ChainElements;
if (chain.Count > 1)
{
X509ChainElementEnumerator enumerator = chain.GetEnumerator();
enumerator.MoveNext(); // el mismo certificado que el pasado por parametro
enumerator.MoveNext();
bool valid = ValidateCertificateByCRL(unsignedProperties, cert, enumerator.Current.Certificate);
if (!valid)
{
var ocspCerts = ValidateCertificateByOCSP(unsignedProperties, cert, enumerator.Current.Certificate);
if (ocspCerts != null)
{
X509Certificate2 startOcspCert = DetermineStartCert(new List<X509Certificate2>(ocspCerts));
if (startOcspCert.IssuerName.Name != enumerator.Current.Certificate.SubjectName.Name)
{
var chainOcsp = CertUtil.GetCertChain(startOcspCert, ocspCerts);
AddCertificate(chainOcsp.ChainElements[1].Certificate, unsignedProperties, true, ocspCerts);
}
}
}
AddCertificate(enumerator.Current.Certificate, unsignedProperties, true, extraCerts);
}
}
示例7: Add
/// <summary cref="ICertificateStore.Add(X509Certificate2)" />
public void Add(X509Certificate2 certificate)
{
if (certificate == null) throw new ArgumentNullException("certificate");
lock (m_lock)
{
IntPtr hStore = IntPtr.Zero;
IntPtr pCertContext = IntPtr.Zero;
// get the DER encoded data.
byte[] buffer = certificate.GetRawCertData();
IntPtr pData = Copy(buffer);
// find the certificate.
try
{
// open store.
hStore = OpenStore(false, true, true);
// check for existing certificate.
pCertContext = FindCertificate(hStore, certificate.Thumbprint);
if (pCertContext != IntPtr.Zero)
{
throw ServiceResultException.Create(
StatusCodes.BadUnexpectedError,
"Certificate is already in the store.\r\nType={0}, Name={1}, Subject={2}",
m_storeType,
m_symbolicName,
certificate.Subject);
}
// add certificate.
Opc.Ua.CertificateFactory.AddCertificateToWindowsStore(
m_storeType == WindowsStoreType.LocalMachine,
m_symbolicName,
certificate);
}
finally
{
if (pData != IntPtr.Zero)
{
Marshal.FreeHGlobal(pData);
}
if (pCertContext != IntPtr.Zero)
{
NativeMethods.CertFreeCertificateContext(pCertContext);
}
if (hStore != IntPtr.Zero)
{
NativeMethods.CertCloseStore(hStore, 0);
}
}
}
}
示例8: Ctor_FileName_Password
[Test] // bug #79028
public void Ctor_FileName_Password ()
{
string tempFile = Path.GetTempFileName ();
try {
using (FileStream fs = File.OpenWrite (tempFile)) {
fs.Write (cert_1, 0, cert_1.Length);
fs.Close ();
}
// password isn't required but supplied
X509Certificate2 cert = new X509Certificate2 (tempFile, "mono");
Assert.IsNotNull (cert.RawData, "#1");
Assert.AreEqual (cert_1.Length, cert.RawData.Length, "#2");
Assert.AreEqual (cert_1, cert.RawData, "#3");
Assert.IsNotNull (cert.GetRawCertData (), "#4");
Assert.AreEqual (cert_1.Length, cert.GetRawCertData ().Length, "#5");
Assert.AreEqual (cert_1, cert.GetRawCertData (), "#6");
}
finally {
File.Delete (tempFile);
}
}
示例9: Ctor_FileName
public void Ctor_FileName ()
{
string tempFile = Path.GetTempFileName ();
try {
using (FileStream fs = File.OpenWrite (tempFile)) {
fs.Write (cert_1, 0, cert_1.Length);
fs.Close ();
}
X509Certificate2 cert = new X509Certificate2 (tempFile);
Assert.IsNotNull (cert.RawData, "#C1");
Assert.AreEqual (cert_1.Length, cert.RawData.Length, "#C2");
Assert.AreEqual (cert_1, cert.RawData, "#C3");
Assert.IsNotNull (cert.GetRawCertData (), "#C4");
Assert.AreEqual (cert_1.Length, cert.GetRawCertData ().Length, "#C5");
Assert.AreEqual (cert_1, cert.GetRawCertData (), "#C6");
Assert.IsFalse (cert.HasPrivateKey, "#C7");
Assert.IsNull (cert.PrivateKey, "#C8");
}
finally {
File.Delete (tempFile);
}
}
示例10: Add
/// <summary cref="ICertificateStore.Add(X509Certificate2)" />
public void Add(X509Certificate2 certificate)
{
if (certificate == null) throw new ArgumentNullException("certificate");
lock (m_lock)
{
byte[] data = null;
// check for certificate file.
Entry entry = Find(certificate.Thumbprint);
if (entry != null)
{
throw new ArgumentException("A certificate with the same thumbprint is already in the store.");
}
if (certificate.HasPrivateKey)
{
data = certificate.Export(X509ContentType.Pkcs12, new System.Security.SecureString());
}
else
{
data = certificate.GetRawCertData();
}
// build file name.
string fileName = GetFileName(certificate);
// write the private and public key.
WriteFile(data, fileName, certificate.HasPrivateKey);
if (certificate.HasPrivateKey)
{
WriteFile(certificate.GetRawCertData(), fileName, false);
}
m_lastDirectoryCheck = DateTime.MinValue;
}
}
示例11: AddToTrustedStore
/// <summary>
/// Adds the certificate to the Trusted Certificate Store
/// </summary>
/// <param name="configuration">The application's configuration which specifies the location of the TrustedStore.</param>
/// <param name="certificate">The certificate to register.</param>
private static void AddToTrustedStore(ApplicationConfiguration configuration, X509Certificate2 certificate)
{
string storePath = null;
if (configuration != null && configuration.SecurityConfiguration != null && configuration.SecurityConfiguration.TrustedPeerCertificates != null)
{
storePath = configuration.SecurityConfiguration.TrustedPeerCertificates.StorePath;
}
if (String.IsNullOrEmpty(storePath))
{
Utils.Trace(Utils.TraceMasks.Information, "WARNING: Trusted peer store not specified.");
return;
}
try
{
ICertificateStore store = configuration.SecurityConfiguration.TrustedPeerCertificates.OpenStore();
if (store == null)
{
Utils.Trace("Could not open trusted peer store. StorePath={0}", storePath);
return;
}
try
{
// check if it already exists.
X509Certificate2 certificate2 = store.FindByThumbprint(certificate.Thumbprint);
if (certificate2 != null)
{
return;
}
Utils.Trace(Utils.TraceMasks.Information, "Adding certificate to trusted peer store. StorePath={0}", storePath);
List<string> subjectName = Utils.ParseDistinguishedName(certificate.Subject);
// check for old certificate.
X509Certificate2Collection certificates = store.Enumerate();
for (int ii = 0; ii < certificates.Count; ii++)
{
if (Utils.CompareDistinguishedName(certificates[ii], subjectName))
{
if (certificates[ii].Thumbprint == certificate.Thumbprint)
{
return;
}
store.Delete(certificates[ii].Thumbprint);
break;
}
}
// add new certificate.
X509Certificate2 publicKey = new X509Certificate2(certificate.GetRawCertData());
store.Add(publicKey);
}
finally
{
store.Close();
}
}
catch (Exception e)
{
Utils.Trace(e, "Could not add certificate to trusted peer store. StorePath={0}", storePath);
}
}
示例12: TestDigest
public void TestDigest()
{
String serviceFingerprint = "96964dfed390fc3a884d897f00bc4446cb9d9429";
String serviceCertificateString = "MIIB8zCCAVygAwIBAgIETSMjbDANBgkqhkiG9w0BAQUFADA+MQswCQYDVQQGEwJCRTEPMA0GA1UEChMGRmVkSUNUMQ8wDQYDVQQLEwZGZWRJQ1QxDTALBgNVBAMTBFRlc3QwHhcNMTEwMTA0MTM0MTAwWhcNMTEwNzAzMTM0MTAwWjA+MQswCQYDVQQGEwJCRTEPMA0GA1UEChMGRmVkSUNUMQ8wDQYDVQQLEwZGZWRJQ1QxDTALBgNVBAMTBFRlc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAIWZDsOroiTb8rlDy6GoUhoG632DGSPjcvHHr/PVT1qsv7+goC6gUPo/4HHxSS67oJZxMABYYLFosBM/wtz5MIBlfCZYcxaVwhxd8HbWtzkBWvaZ9UobWoa83DL5ns1g4zOYkYA4KMBzDTP/s36dVT4vnB0WQvjqxHFtheoNacDNAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAecWebvuTk04zuYO7npHgpNi0IgmOafBW9mmeQBWq7gJlm5sy8nK/HJjtmRxjnRzo+iQ89On5Acipg5H0PIH5HVLf4zoLdH86tohzj0ohpw+rUma4aCwhyQfO+QqS2PokHM7elF0yUNYrZdoY3InoYuXvS1oejGeOJ6wiZ4dqN/c=";
X509Certificate2 serviceCertificate = new X509Certificate2(Convert.FromBase64String(serviceCertificateString));
Assert.NotNull(serviceCertificate);
String resultServiceCertificateString = Convert.ToBase64String(serviceCertificate.GetRawCertData());
Assert.True(serviceCertificateString.Equals(resultServiceCertificateString));
byte[] actualServiceFingerprint = SHA1.Create().ComputeHash(serviceCertificate.GetRawCertData());
String resultFingerprint = BitConverter.ToString(actualServiceFingerprint).Replace("-", "").ToLower();
Console.WriteLine("result: " + resultFingerprint);
Assert.True(serviceFingerprint.Equals(resultFingerprint));
}
示例13: CompareCertificates
/// <summary>
/// Compares two certificates.
/// </summary>
protected static void CompareCertificates(X509Certificate2 expected, X509Certificate2 actual, bool allowNull)
{
bool equal = true;
if (expected == null)
{
equal = actual == null;
// accept everything if no expected certificate and nulls are allowed.
if (allowNull)
{
equal = true;
}
}
else if (actual == null)
{
equal = allowNull;
}
else if (!Utils.IsEqual(expected.GetRawCertData(), actual.GetRawCertData()))
{
equal = false;
}
if (!equal)
{
throw ServiceResultException.Create(
StatusCodes.BadCertificateInvalid,
"Certificate mismatch. Expecting '{0}'/{1},. Received '{2}'/{3}.",
(expected != null) ? expected.Subject : "(null)",
(expected != null) ? expected.Thumbprint : "(null)",
(actual != null) ? actual.Subject : "(null)",
(actual != null) ? actual.Thumbprint : "(null)");
}
}
示例14: Export_SerializedCert
public void Export_SerializedCert ()
{
X509Certificate cert = new X509Certificate (cert1);
byte[] data = cert.Export (X509ContentType.SerializedCert);
// usable
X509Certificate2 c = new X509Certificate2 (data);
Assert.AreEqual (cert1, c.GetRawCertData (), "Equals");
}
示例15: WriteCertificate
public static void WriteCertificate(X509Certificate2 cert)
{
byte[] certBytes = cert.GetRawCertData();
string fileName = string.Format("{0}.cer", cert.SerialNumber);
File.WriteAllBytes(fileName, certBytes);
Console.WriteLine("Wrote: " + fileName);
}