本文整理汇总了C#中Certificate类的典型用法代码示例。如果您正苦于以下问题:C# Certificate类的具体用法?C# Certificate怎么用?C# Certificate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Certificate类属于命名空间,在下文中一共展示了Certificate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_create_self_signed_cert
public void should_create_self_signed_cert()
{
var key = new Key(512);
var cert = new Certificate(
r =>
{
r.Dn = "cn=root.test";
r.PublicKey = key.PublicKey;
r.NotBefore = DateTime.UtcNow;
r.NotAfter = r.NotBefore.AddYears(10);
},
i =>
{
i.DistinguishedName = "cn=root.test";
i.Key = key;
});
Console.WriteLine(cert.ToString());
string pem = cert.ToPem();
Console.WriteLine(pem);
var certificate = new Certificate(pem);
Console.WriteLine(certificate.ToString());
}
示例2: SecureChannelException
public SecureChannelException(SecureChannelCode code, IPEndPoint peerEP, Certificate peerCertificate, string message, Exception innerException)
: base(message, innerException)
{
_code = code;
_peerEP = peerEP;
_peerCertificate = peerCertificate;
}
示例3: Update
public Certificate Update(Certificate certificate)
{
Certificate cer = DbContext.Certificates.FirstOrDefault(s=>s.ID == certificate.ID);
if (cer == null)
{
cer = new Certificate();
DbContext.Certificates.Add(cer);
}
cer.DistingishedName = certificate.DistingishedName;
cer.HashAlgorithm = certificate.HashAlgorithm;
cer.PublicKeyLength = certificate.PublicKeyLength;
cer.CER = certificate.CER;
cer.LinkedGroupId = certificate.LinkedGroupId;
cer.RequestedByUser = certificate.RequestedByUser;
cer.RequestedOn = certificate.RequestedOn;
cer.UserFriendlyName = certificate.UserFriendlyName;
if (cer.LinkedGroupId == 0)
{
cer.LinkedGroupId = 1; // Default to everyone
}
DbContext.SaveChanges();
return cer;
}
示例4: GetSignedCertificate
public static Certificate GetSignedCertificate(Uri apiUri, CertificateStore certStore)
{
using (WebClient client = new WebClient())
{
client.Headers.Add("User-Agent", GetUserAgent());
byte[] data = client.DownloadData(apiUri.AbsoluteUri + "?cmd=dlc&email=" + certStore.Certificate.IssuedTo.EmailAddress.Address);
using (BinaryReader bR = new BinaryReader(new MemoryStream(data)))
{
int errorCode = bR.ReadInt32();
if (errorCode != 0)
{
string message = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadInt32()));
string remoteStackTrace = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadInt32()));
throw new BitChatException(message);
}
Certificate cert = new Certificate(bR);
if (!cert.IssuedTo.EmailAddress.Equals(certStore.Certificate.IssuedTo.EmailAddress) || (cert.PublicKeyEncryptionAlgorithm != certStore.PrivateKey.Algorithm) || (cert.PublicKeyXML != certStore.PrivateKey.GetPublicKey()))
throw new BitChatException("Invalid signed certificate received. Please try again.");
return cert;
}
}
}
示例5: BitChatNetwork
public BitChatNetwork(MailAddress peerEmailAddress, string sharedSecret, BinaryID networkID, Certificate[] knownPeerCerts, IBitChatNetworkManager networkManager, ISecureChannelSecurityManager securityManager)
{
_type = BitChatNetworkType.PrivateChat;
_peerEmailAddress = peerEmailAddress;
_sharedSecret = sharedSecret;
_networkManager = networkManager;
_securityManager = securityManager;
LoadPeers(knownPeerCerts);
if (knownPeerCerts.Length > 0)
_peerName = knownPeerCerts[0].IssuedTo.Name;
if (networkID == null)
{
//compute network id
HashAlgorithm hash = HashAlgorithm.Create("SHA1");
byte[] peerEmailAddressHash = hash.ComputeHash(Encoding.UTF8.GetBytes(_peerEmailAddress.Address.ToLower()));
byte[] selfEmailAddressHash = hash.ComputeHash(Encoding.UTF8.GetBytes(networkManager.GetLocalCredentials().Certificate.IssuedTo.EmailAddress.Address.ToLower()));
byte[] salt = new byte[20];
for (int i = 0; i < 20; i++)
{
salt[i] = (byte)(peerEmailAddressHash[i] ^ selfEmailAddressHash[i]);
}
_networkID = new BinaryID(PBKDF2.CreateHMACSHA1(_sharedSecret, salt, 200000).GetBytes(20));
}
else
{
_networkID = networkID;
}
}
示例6: BitChatService
public BitChatService(BitChatProfile profile, Certificate[] trustedRootCertificates, SecureChannelCryptoOptionFlags supportedCryptoOptions, InvalidCertificateEvent invalidCertEventHandler)
{
//verify root certs
foreach (Certificate trustedCert in trustedRootCertificates)
trustedCert.Verify(trustedRootCertificates);
//verify profile cert
profile.LocalCertificateStore.Certificate.Verify(trustedRootCertificates);
_invalidCertEventHandler = invalidCertEventHandler;
_manager = new InternalBitChatService(this, profile, trustedRootCertificates, supportedCryptoOptions);
foreach (BitChatProfile.BitChatInfo bitChatInfo in profile.BitChatInfoList)
{
if (bitChatInfo.Type == BitChatNetworkType.PrivateChat)
_bitChats.Add(_manager.CreateBitChat(new MailAddress(bitChatInfo.NetworkNameOrPeerEmailAddress), bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.PeerCertificateList, bitChatInfo.SharedFileList, bitChatInfo.TrackerURIs));
else
_bitChats.Add(_manager.CreateBitChat(bitChatInfo.NetworkNameOrPeerEmailAddress, bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.PeerCertificateList, bitChatInfo.SharedFileList, bitChatInfo.TrackerURIs));
}
//check profile cert revocation
ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, new Certificate[] { profile.LocalCertificateStore.Certificate });
//check trusted root cert revocation
ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, trustedRootCertificates);
}
示例7: BindData
private void BindData()
{
Certificate all = new Certificate();
all.GetAllCertificates();
uiRadListViewCircularsPublic.DataSource = all.DefaultView;
uiRadListViewCircularsPublic.DataBind();
}
示例8: UpdateCertificate
public bool UpdateCertificate(string propertyReference, string certificateReference, Certificate certificate)
{
Check.If(propertyReference).IsNotNullOrEmpty();
Check.If(certificateReference).IsNotNullOrEmpty();
Check.If(certificate).IsNotNull();
return _certificateRepository.UpdateCertificate(propertyReference, certificateReference, certificate);
}
示例9: saveCertificate
public static void saveCertificate(string fileName, Certificate cert)
{
XmlSerializer s = new XmlSerializer(typeof(Certificate));
TextWriter tw = new StreamWriter(@fileName);
s.Serialize(tw, cert);
Log(m_TAG, "saving Ceritifcate");
tw.Close();
}
示例10: ValidStartDateTest
public void ValidStartDateTest()
{
Certificate target = new Certificate();
DateTime expected = DateTime.UtcNow;
target.ValidStartDate = expected;
DateTime actual = target.ValidStartDate;
Assert.Equal(expected, actual);
}
示例11: Eksport
public Eksport()
{
this.InitializeComponent();
this.con = new Connection();
this.c = new Certificate();
this.savePath = "";
this.licensePath = "";
this.pass = "";
}
示例12: CreateCertificate
public string CreateCertificate(string propertyReference, Certificate certificate)
{
Check.If(propertyReference).IsNotNullOrEmpty();
Check.If(certificate).IsNotNull();
var result = _certificateRepository.CreateCertificate(propertyReference,
certificate.CreateReference(_referenceGenerator));
return result ? certificate.CertificateReference : null;
}
示例13: btnDeleteCurrentFile_Click
protected void btnDeleteCurrentFile_Click(object sender, EventArgs e)
{
Certificate objData = new Certificate();
objData = CurrentCertificate;
objData.SetColumnNull(Certificate.ColumnNames.Path);
objData.Save();
txtCurrentFile.Text = "";
txtCurrentFile.Visible = false;
btnDeleteCurrentFile.Visible = false;
lblCurrentFile.Visible = false;
}
示例14: NotifyClientCertificate
public override void NotifyClientCertificate(Certificate clientCertificate)
{
X509CertificateStructure[] chain = clientCertificate.GetCertificateList();
Console.WriteLine("DTLS server received client certificate chain of length " + chain.Length);
for (int i = 0; i != chain.Length; i++)
{
X509CertificateStructure entry = chain[i];
// TODO Create fingerprint based on certificate signature algorithm digest
Console.WriteLine(" fingerprint:SHA-256 " + TlsTestUtilities.Fingerprint(entry) + " ("
+ entry.Subject + ")");
}
}
示例15: UpdateLoadCertificate
private static Task UpdateLoadCertificate(string resourceGroupName, string certificateName, string location, string pathToPfxFile, string certificatePassword)
{
var pfxAsBytes = File.ReadAllBytes(pathToPfxFile);
var pfxBlob = Convert.ToBase64String(pfxAsBytes);
var certificate = new Certificate
{
Location = location,
Password = certificatePassword,
PfxBlob = pfxBlob
};
return _websiteClient.Certificates.CreateOrUpdateCertificateAsync(resourceGroupName, certificateName, certificate);
}