本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Certificate2类的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2类的具体用法?C# X509Certificate2怎么用?C# X509Certificate2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
X509Certificate2类属于System.Security.Cryptography.X509Certificates命名空间,在下文中一共展示了X509Certificate2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnbindInternal
protected Saml2Request UnbindInternal(HttpRequestBase request, Saml2Request saml2RequestResponse, X509Certificate2 signatureValidationCertificate)
{
if (request == null)
throw new ArgumentNullException("request");
if (saml2RequestResponse == null)
throw new ArgumentNullException("saml2RequestResponse");
if (signatureValidationCertificate == null)
{
throw new ArgumentNullException("signatureValidationCertificate");
}
if (signatureValidationCertificate.PublicKey == null)
{
throw new ArgumentException("No Public Key present in Signature Validation Certificate.");
}
if (!(signatureValidationCertificate.PublicKey.Key is DSA || signatureValidationCertificate.PublicKey.Key is RSACryptoServiceProvider))
{
throw new ArgumentException("The Public Key present in Signature Validation Certificate must be either DSA or RSACryptoServiceProvider.");
}
saml2RequestResponse.SignatureValidationCertificate = signatureValidationCertificate;
return saml2RequestResponse;
}
示例2: Client
public Client(String host, Int32 port)
{
try
{
clientName = Dns.GetHostName();
}
catch (SocketException se)
{
MessageBox.Show("ERROR: Could not retrieve client's DNS hostname. Please try again." + se.Message + ".", "Client Socket Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
serverName = host;
gamePort = port;
client = new TcpClient(host, port);
netStream = client.GetStream();
reader = new StreamReader(netStream);
writer = new StreamWriter(netStream);
ssl = new SslStream(netStream, false, new RemoteCertificateValidationCallback(ValidateCert));
cert = new X509Certificate2("server.crt");
ssl.AuthenticateAsClient(serverName);
writer.AutoFlush = true;
}
示例3: X509ChainElement
// constructors
// only accessible from X509Chain.ChainElements
internal X509ChainElement (X509Certificate2 certificate)
{
this.certificate = certificate;
// so far String.Empty is the only thing I've seen.
// The interesting stuff is inside X509ChainStatus.Information
info = String.Empty;
}
示例4: GetSecurityTokenHandler
private JsonWebSecurityTokenHandler GetSecurityTokenHandler(string audience,
string authMetadataEndpoint,
X509Certificate2 currentCertificate)
{
JsonWebSecurityTokenHandler jsonTokenHandler = new JsonWebSecurityTokenHandler();
jsonTokenHandler.Configuration = new Microsoft.IdentityModel.Tokens.SecurityTokenHandlerConfiguration();
jsonTokenHandler.Configuration.AudienceRestriction = new Microsoft.IdentityModel.Tokens.AudienceRestriction(AudienceUriMode.Always);
jsonTokenHandler.Configuration.AudienceRestriction.AllowedAudienceUris.Add(
new Uri(audience, UriKind.RelativeOrAbsolute));
jsonTokenHandler.Configuration.CertificateValidator = X509CertificateValidator.None;
jsonTokenHandler.Configuration.IssuerTokenResolver =
SecurityTokenResolver.CreateDefaultSecurityTokenResolver(
new ReadOnlyCollection<SecurityToken>(new List<SecurityToken>(
new SecurityToken[]
{
new X509SecurityToken(currentCertificate)
})), false);
Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry issuerNameRegistry =
new Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry();
issuerNameRegistry.AddTrustedIssuer(currentCertificate.Thumbprint, Config.ExchangeApplicationIdentifier);
jsonTokenHandler.Configuration.IssuerNameRegistry = issuerNameRegistry;
return jsonTokenHandler;
}
示例5: assinarEmLote
public string assinarEmLote(string xml, X509Certificate2 certificado)
{
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = false;
doc.LoadXml(xml);
XmlNodeList atributos = doc.ChildNodes.Item(0).ChildNodes;
for ( int count = 0; count < atributos.Count; count++ )
{
if (!atributos.Item(count).Name.Equals("RPS"))
continue;
XmlNode rpsNode = atributos.Item(count);
string referencia = DefinirReferenciaParaAssinaturaRPS(rpsNode);
string referenciaCriptografada = CriptografarReferencia(referencia, certificado);
rpsNode.ChildNodes.Item(0).InnerText = referenciaCriptografada;
}
return doc.OuterXml;
}
示例6: SignatureProcessor
public SignatureProcessor(X509Certificate2 certificate, ProtocolSettings discoveryInfo)
{
this.Certificate = certificate;
this.discoveryInfo = discoveryInfo;
this.SHA1SignatureName = ProtocolStrings.SignatureAlgorithmSHA1Uri;
this.references = new List<ReferenceEntry>();
}
示例7: Encrypt
/// <summary>
/// Encrypts the DecryptedPassword using the EncryptionAlgorithm and places the result in Password
/// </summary>
public override void Encrypt(X509Certificate2 certificate, byte[] senderNonce, string securityPolicyUri)
{
if (m_decryptedPassword == null)
{
m_password = null;
return;
}
// handle no encryption.
if (String.IsNullOrEmpty(securityPolicyUri) || securityPolicyUri == SecurityPolicies.None)
{
m_password = new UTF8Encoding().GetBytes(m_decryptedPassword);
m_encryptionAlgorithm = null;
return;
}
// encrypt the password.
byte[] dataToEncrypt = Utils.Append(new UTF8Encoding().GetBytes(m_decryptedPassword), senderNonce);
EncryptedData encryptedData = SecurityPolicies.Encrypt(
certificate,
securityPolicyUri,
dataToEncrypt);
m_password = encryptedData.Data;
m_encryptionAlgorithm = encryptedData.Algorithm;
}
示例8: Decrypt
public void Decrypt(XmlDocument document, X509Certificate2 encryptionCert)
{
var assertion = document.FindChild(EncryptedAssertion);
if (assertion == null) return; // Not encrypted, shame on them.
var data = document.EncryptedChild("EncryptedData");
var keyElement = assertion.EncryptedChild("EncryptedKey");
var encryptedData = new EncryptedData();
encryptedData.LoadXml(data);
var encryptedKey = new EncryptedKey();
encryptedKey.LoadXml(keyElement);
var encryptedXml = new EncryptedXml(document);
// Get encryption secret key used by decrypting with the encryption certificate's private key
var secretKey = GetSecretKey(encryptedKey, encryptionCert.PrivateKey);
// Seed the decryption algorithm with secret key and then decrypt
var algorithm = GetSymmetricBlockEncryptionAlgorithm(encryptedData.EncryptionMethod.KeyAlgorithm);
algorithm.Key = secretKey;
var decryptedBytes = encryptedXml.DecryptData(encryptedData, algorithm);
// Put decrypted xml elements back into the document in place of the encrypted data
encryptedXml.ReplaceData(assertion, decryptedBytes);
}
示例9: AzureCurrentDeployment
public AzureCurrentDeployment(string deploymentPrivateId, string subscriptionId, X509Certificate2 certificate, IProvisioningObserver observer = null)
{
_subscriptionId = subscriptionId;
_certificate = certificate;
_deploymentPrivateId = deploymentPrivateId;
_observer = observer;
}
示例10: BuildService
/// <summary>
/// Create a service connection to google.
/// </summary>
/// <param name="userEmail">The API email to use for authentication.</param>
/// <param name="gService">The type of service to connect to.</param>
/// <returns>Returns an open connection to the google api service, or null.</returns>
private static BaseClientService BuildService(string userEmail, GoogleServices gService = GoogleServices.Directory)
{
X509Certificate2 certificate = new X509Certificate2(Properties.Resources.gsd_api,"notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
{
Scopes = Scopes,
User = userEmail
}.FromCertificate(certificate));
switch (gService)
{
case GoogleServices.Directory:
DirectoryService directoryService = new DirectoryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "GSD GAMS",
});
return directoryService;
case GoogleServices.Drive:
DriveService driveService = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "GSD GAMS",
});
return driveService;
}
return null;
}
示例11: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "idsrv4test.pfx"), "idsrv3test");
var builder = services.AddIdentityServer(options =>
{
options.SigningCertificate = cert;
});
builder.AddInMemoryClients(Clients.Get());
builder.AddInMemoryScopes(Scopes.Get());
builder.AddInMemoryUsers(Users.Get());
builder.AddCustomGrantValidator<CustomGrantValidator>();
// for the UI
services
.AddMvc()
.AddRazorOptions(razor =>
{
razor.ViewLocationExpanders.Add(new CustomViewLocationExpander());
});
services.AddTransient<UI.Login.LoginService>();
services.AddTransient<UI.SignUp.SignUpService>();
services.AddTransient<ISmsSender, MessageServices>();
services.Configure<ASPmsSercetCredentials>(Configuration);
}
示例12: CreateStorageAcc
/// <summary>
/// Method to submit the request to create new storage account and return request token.
/// </summary>
/// <param name="subscriptionId">Subscription id</param>
/// <param name="cert">Auth certificate</param>
/// <param name="input">Input required to create new storage acc</param>
/// <returns>Token to track the progress of storage account creation</returns>
public static string CreateStorageAcc(string subscriptionId, CreateStorageServiceInput input, X509Certificate2 cert)
{
ClientOutputMessageInspector messageInspector;
IServiceManagement serviceManager = ServiceInitializer.Get(cert, out messageInspector);
serviceManager.CreateStorageAccount(subscriptionId, input);
return messageInspector.ResponseMessage.Headers["x-ms-request-id"];
}
示例13: AzureDiscovery
public AzureDiscovery(string subscriptionId, X509Certificate2 certificate, IProvisioningObserver observer = null)
{
_subscriptionId = subscriptionId;
_certificate = certificate;
_observer = observer;
_policies = new RetryPolicies(observer);
}
示例14: Add
public int Add(X509Certificate2 certificate)
{
if (certificate == null)
throw new ArgumentNullException("certificate");
return List.Add(certificate);
}
示例15: DeploymentServerCertificateValidator
public DeploymentServerCertificateValidator(X509Certificate2 allowedCertificate) {
if (allowedCertificate == null) {
throw new ArgumentNullException("allowedCertificate");
}
this.allowedCertificate = allowedCertificate;
}