private static string SignXml(XmlDocument unsignedXml, AsymmetricAlgorithm key) { if (unsignedXml.DocumentElement == null) { throw new ArgumentNullException("unsignedXml"); } // Create a reference to be signed. Blank == Everything var emptyReference = new Reference { Uri = "" }; // Add an enveloped transformation to the reference. var envelope = new XmlDsigEnvelopedSignatureTransform(); emptyReference.AddTransform(envelope); var signedXml = new SignedXml(unsignedXml) { SigningKey = key }; signedXml.AddReference(emptyReference); signedXml.ComputeSignature(); var digitalSignature = signedXml.GetXml(); unsignedXml.DocumentElement.AppendChild( unsignedXml.ImportNode(digitalSignature, true)); var signedXmlOut = new StringBuilder(); using (var swOut = new StringWriter(signedXmlOut)) { unsignedXml.Save(swOut); } return signedXmlOut.ToString(); }
public override void SetKey(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException("key"); Contract.EndContractBlock(); _rsaKey = (RSA) key; _rsaOverridesDecrypt = default(bool?); }
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) { AsymmetricSignatureDeformatter deformatter = (AsymmetricSignatureDeformatter) CryptoConfig.CreateFromName(base.DeformatterAlgorithm); deformatter.SetKey(key); deformatter.SetHashAlgorithm("SHA1"); return deformatter; }
internal static IEnumerable<XmlElement> Decrypt(this IEnumerable<XmlElement> elements, AsymmetricAlgorithm key) { foreach (var element in elements) { yield return element.Decrypt(key); } }
internal IdentityProvider(IdentityProviderElement config, ISPOptions spOptions) { singleSignOnServiceUrl = config.DestinationUrl; EntityId = new EntityId(config.EntityId); binding = config.Binding; AllowUnsolicitedAuthnResponse = config.AllowUnsolicitedAuthnResponse; metadataUrl = config.MetadataUrl; LoadMetadata = config.LoadMetadata; this.spOptions = spOptions; var certificate = config.SigningCertificate.LoadCertificate(); if (certificate != null) { signingKey = certificate.PublicKey.Key; } try { if (LoadMetadata) { DoLoadMetadata(); } Validate(); } catch (WebException) { // If we had a web exception, the metadata failed. It will // be automatically retried. } }
/// <summary> /// Initializes a new instance of the <see cref="RsaCryptographicKey" /> class. /// </summary> /// <param name="key">The RSA crypto service provider.</param> /// <param name="algorithm">The algorithm.</param> internal RsaCryptographicKey(RSA key, AsymmetricAlgorithm algorithm) { Requires.NotNull(key, "key"); this.key = key; this.algorithm = algorithm; }
public RSAPKCS1SignatureFormatter(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException(nameof(key)); _rsaKey = (RSA)key; }
public override void SetKey(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException(nameof(key)); _rsaKey = (RSA)key; }
public virtual AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) { AsymmetricSignatureFormatter item; item = (AsymmetricSignatureFormatter) CryptoConfig.CreateFromName(_strFormatter); item.SetKey(key); return item; }
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) { var asymmetricSignatureDeformatter = (AsymmetricSignatureDeformatter)CryptoConfig.CreateFromName(DeformatterAlgorithm); asymmetricSignatureDeformatter.SetKey(key); asymmetricSignatureDeformatter.SetHashAlgorithm("SHA256"); return asymmetricSignatureDeformatter; }
public DSASignatureFormatter(AsymmetricAlgorithm key) : this() { if (key == null) throw new ArgumentNullException(nameof(key)); _dsaKey = (DSA)key; }
protected RSAPKCS1Algorithm(string hashAlgorithm, CryptographicKey publicKey = null, CryptographicKey privateKey = null) : this(hashAlgorithm) { this.disposePublicKey = true; this.disposePrivateKey = true; if (publicKey != null) { this.publicKey = GetAlgorithmFromCryptographicKey(publicKey); if (this.publicKey.KeySize < 2048) { this.Dispose(); throw new ArgumentException("Key size must be at 2048bits"); } } if (privateKey != null) { this.privateKey = GetAlgorithmFromCryptographicKey(privateKey); if (this.privateKey.KeySize < 2048) { this.Dispose(); throw new ArgumentException("Key size must be at 2048bits"); } } }
public HttpConnection(Socket sock, EndPointListener epl, bool secure, X509Certificate2 cert, AsymmetricAlgorithm key) { this.sock = sock; this.epl = epl; this.secure = secure; this.key = key; var networkstream = new NetworkStream(sock, false); if (secure) { var sslstream = new System.Net.Security.SslStream(networkstream); sslstream.AuthenticateAsServer(cert); stream = sslstream; } else { stream = networkstream; } timer = new Timer(OnTimeout, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); if (buffer == null) { buffer = new byte[BufferSize]; } Init(); }
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var provider = (RSACryptoServiceProvider)key; // The provider is probably using the default ProviderType. That's // a problem, because it doesn't support SHA256. Let's do some // black magic and create a new provider of a type that supports // SHA256 without the user ever knowing we fix this. This is what // is done in X509AsymmetricKey.GetSignatureFormatter if // http://www.w3.org/2001/04/xmldsig-more#rsa-sha256 isn't // a known algorithm, so users kind of expect this to be handled // for them magically. var cspParams = new CspParameters(); cspParams.ProviderType = 24; //PROV_RSA_AES cspParams.KeyContainerName = provider.CspKeyContainerInfo.KeyContainerName; cspParams.KeyNumber = (int)provider.CspKeyContainerInfo.KeyNumber; SetMachineKeyFlag(provider, cspParams); cspParams.Flags |= CspProviderFlags.UseExistingKey; provider = new RSACryptoServiceProvider(cspParams); var f = new RSAPKCS1SignatureFormatter(provider); f.SetHashAlgorithm(typeof(SHA256Managed).FullName); return f; }
/// <summary> /// Verifies the signature of the XmlElement instance using the key given as a parameter. /// </summary> /// <param name="el">The element.</param> /// <param name="alg">The algorithm.</param> /// <returns><code>true</code> if the element's signature can be verified. <code>false</code> if the signature could /// not be verified.</returns> /// <exception cref="InvalidOperationException">if the XmlDocument instance does not contain a signed XML element.</exception> public static bool CheckSignature(XmlElement el, AsymmetricAlgorithm alg) { // CheckDocument(element); var signedXml = RetrieveSignature(el); return signedXml.CheckSignature(alg); }
/// <summary> /// Verifies the signature of the XmlDocument instance using the key given as a parameter. /// </summary> /// <param name="doc">The doc.</param> /// <param name="alg">The algorithm.</param> /// <returns><code>true</code> if the document's signature can be verified. <code>false</code> if the signature could /// not be verified.</returns> /// <exception cref="InvalidOperationException">if the XmlDocument instance does not contain a signed XML document.</exception> public static bool CheckSignature(XmlDocument doc, AsymmetricAlgorithm alg) { CheckDocument(doc); var signedXml = RetrieveSignature(doc); return signedXml.CheckSignature(alg); }
public RSAPKCS1SignatureDeformatter(AsymmetricAlgorithm key) { if (key == null) { throw new ArgumentNullException("key"); } this._rsaKey = (RSA) key; }
static void loadPfx() { cert1 = new X509Certificate2(c1pfx, "111test"); cert2 = new X509Certificate2(c2pfx, "111test"); sgcert = new X509Certificate2(sgpfx, "111test"); sgpk = sgcert.PrivateKey; }
public DSASignatureDeformatter(AsymmetricAlgorithm key) : this() { if (key == null) { throw new ArgumentNullException("key"); } this._dsaKey = (DSA) key; }
public RequestTokenService(Environments.Environment environment, string consumerKey, AsymmetricAlgorithm privateKey) : base(consumerKey, privateKey) { this.environment = environment; // ignore possible security certificate errors ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; }
public RSAOAEPKeyExchangeDeformatter(AsymmetricAlgorithm key) { if (key == null) { throw new ArgumentNullException("key"); } this._rsaKey = (RSA) key; }
/// <summary> /// Initializes a new instance of the <see cref="RsaCryptographicKey" /> class. /// </summary> /// <param name="publicKey">The public key.</param> /// <param name="keyIdentifier">The key identifier that may be used to query the keychain.</param> /// <param name="algorithm">The algorithm.</param> internal RsaCryptographicKey(SecKey publicKey, string keyIdentifier, AsymmetricAlgorithm algorithm) { Requires.NotNull(publicKey, "publicKey"); this.publicKey = publicKey; this.keyIdentifier = keyIdentifier; this.algorithm = algorithm; }
public static string SignXmlFile(string sourceXml, AsymmetricAlgorithm key) { var unsignedXml = new XmlDocument { PreserveWhitespace = false }; unsignedXml.LoadXml(sourceXml); return SignXml(unsignedXml, key); }
public static bool XmlFileIsValid(string signedXmlPath, AsymmetricAlgorithm key) { var signedXml = new XmlDocument { PreserveWhitespace = false }; signedXml.Load(signedXmlPath); return XmlIsValid(signedXml, key); }
public override void SetKey(AsymmetricAlgorithm key) { if (key == null) { throw new ArgumentNullException("key"); } this._rsaKey = (RSA) key; }
/// <summary> /// This constructor allows the caller to provide a preloaded private key for use /// when OAuth calls are made. /// </summary> /// <param name="consumerKey"></param> /// <param name="privateKey"></param> public Connector(string consumerKey, AsymmetricAlgorithm privateKey) { this.ConsumerKey = consumerKey; this.privateKey = privateKey; // Turns the handling of a 100 HTTP server response ON System.Net.ServicePointManager.Expect100Continue = true; }
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException(nameof(key)); var f = new RSAPKCS1SignatureFormatter(key); f.SetHashAlgorithm(SHA_512); return f; }
public static byte[] GetSecretKey(EncryptedKey encryptedKey, AsymmetricAlgorithm privateKey) { var keyAlgorithm = encryptedKey.EncryptionMethod.KeyAlgorithm; var asymmetricAlgorithm = GetAsymmetricKeyTransportAlgorithm(keyAlgorithm); asymmetricAlgorithm.FromXmlString(privateKey.ToXmlString(true)); var useOaep = keyAlgorithm == EncryptedXml.XmlEncRSAOAEPUrl; return asymmetricAlgorithm.Decrypt(encryptedKey.CipherData.CipherValue, useOaep); }
private static bool Adapter <T>(System.Security.Cryptography.AsymmetricAlgorithm algorithm, Action <T> action) where T : System.Security.Cryptography.AsymmetricAlgorithm { if (algorithm is T) { action((T)algorithm); return(true); } return(false); }
public override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) { if (key == null) throw new ArgumentNullException("key"); RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(key); formatter.SetHashAlgorithm("SHA256"); return formatter; }
/// <include file='doc\DSASignatureDeformatter.uex' path='docs/doc[@for="DSASignatureDeformatter.DSASignatureDeformatter1"]/*' /> public DSASignatureDeformatter(AsymmetricAlgorithm key) { SetKey(key); // The hash algorithm is always SHA1 _strOID = CryptoConfig.MapNameToOID("SHA1"); }
public RSAPKCS1SignatureDeformatter(AsymmetricAlgorithm key) { SetKey(key); }
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.RSAOAEPKeyExchangeDeformatter" /> class with the specified key.</summary><param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the private key. </param><exception cref="T:System.ArgumentNullException"><paramref name="key " />is null.</exception> public RSAOAEPKeyExchangeDeformatter(AsymmetricAlgorithm key) { throw new NotImplementedException(); }
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.DSASignatureDeformatter" /> class with the specified key.</summary> /// <param name="key">The instance of Digital Signature Algorithm (<see cref="T:System.Security.Cryptography.DSA" />) that holds the key. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key" /> is null.</exception> public DSASignatureDeformatter(AsymmetricAlgorithm key) { this.SetKey(key); }
public RSAPKCS1SignatureFormatter(AsymmetricAlgorithm key !!) {
/* Import/export functions */ // We can provide a default implementation of FromXmlString because we require // every RSA implementation to implement ImportParameters // All we have to do here is parse the XML. /// <include file='doc\rsa.uex' path='docs/doc[@for="RSA.FromXmlString"]/*' /> public override void FromXmlString(String xmlString) { if (xmlString == null) { throw new ArgumentNullException("xmlString"); } RSAParameters rsaParams = new RSAParameters(); Parser p = new Parser(xmlString); SecurityElement topElement = p.GetTopElement(); // Modulus is always present String modulusString = topElement.SearchForTextOfLocalName("Modulus"); if (modulusString == null) { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "RSA", "Modulus")); } rsaParams.Modulus = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(modulusString)); // Exponent is always present String exponentString = topElement.SearchForTextOfLocalName("Exponent"); if (exponentString == null) { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "RSA", "Exponent")); } rsaParams.Exponent = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(exponentString)); // P is optional String pString = topElement.SearchForTextOfLocalName("P"); if (pString != null) { rsaParams.P = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(pString)); } // Q is optional String qString = topElement.SearchForTextOfLocalName("Q"); if (qString != null) { rsaParams.Q = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(qString)); } // DP is optional String dpString = topElement.SearchForTextOfLocalName("DP"); if (dpString != null) { rsaParams.DP = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(dpString)); } // DQ is optional String dqString = topElement.SearchForTextOfLocalName("DQ"); if (dqString != null) { rsaParams.DQ = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(dqString)); } // InverseQ is optional String inverseQString = topElement.SearchForTextOfLocalName("InverseQ"); if (inverseQString != null) { rsaParams.InverseQ = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(inverseQString)); } // D is optional String dString = topElement.SearchForTextOfLocalName("D"); if (dString != null) { rsaParams.D = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(dString)); } ImportParameters(rsaParams); }
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.RSAPKCS1KeyExchangeFormatter" /> class with the specified key.</summary> /// <param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the public key. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key " />is null.</exception> public RSAPKCS1KeyExchangeFormatter(AsymmetricAlgorithm key) { this.SetRSAKey(key); }
public DSASignatureDeformatter(AsymmetricAlgorithm key) : base() { SetKey(key); }
public RSAPKCS1KeyExchangeDeformatter(AsymmetricAlgorithm key) { SetKey(key); }
public override void SetKey(AsymmetricAlgorithm key) { }
/// <summary>当在派生类中重写时,设置用于加密机密信息的公钥。</summary> /// <param name="key">包含公钥的 <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> 实现的实例。</param> public abstract void SetKey(AsymmetricAlgorithm key);
public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) { return(base.CreateDeformatter(key)); }
public DSASignatureFormatter(AsymmetricAlgorithm key) { }
/************************* PUBLIC METHODS *************************/ /// <include file='doc\RSAOAEPKeyExchangeFormatter.uex' path='docs/doc[@for="RSAOAEPKeyExchangeFormatter.SetKey"]/*' /> public override void SetKey(AsymmetricAlgorithm key) { _rsaKey = (RSA)key; }
public ECOpenSsl(AsymmetricAlgorithm owner) { _key = new Lazy <SafeEcKeyHandle>(() => GenerateKeyLazy(owner)); }
/// <summary>Sets the public key to use for encrypting the key exchange data.</summary> /// <param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the public key. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key " />is null.</exception> public override void SetKey(AsymmetricAlgorithm key) { this.SetRSAKey(key); }
public override void SetKey(AsymmetricAlgorithm key) { ArgumentNullException.ThrowIfNull(key); _rsaKey = (RSA)key; }
/// <summary>Sets the private key to use for creating the signature.</summary><param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the private key. </param><exception cref="T:System.ArgumentNullException"><paramref name="key" /> is null.</exception> public override void SetKey(AsymmetricAlgorithm key) { throw new NotImplementedException(); }
public RSAPKCS1KeyExchangeDeformatter(AsymmetricAlgorithm key) { ArgumentNullException.ThrowIfNull(key); _rsaKey = (RSA)key; }
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.RSAPKCS1SignatureFormatter" /> class with the specified key.</summary><param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the private key. </param><exception cref="T:System.ArgumentNullException"><paramref name="key" /> is null.</exception> public RSAPKCS1SignatureFormatter(AsymmetricAlgorithm key) { throw new NotImplementedException(); }
// We can provide a default implementation of FromXmlString because we require // every DSA implementation to implement ImportParameters // All we have to do here is parse the XML. public override void FromXmlString(String xmlString) { if (xmlString == null) { throw new ArgumentNullException("xmlString"); } DSAParameters dsaParams = new DSAParameters(); Parser p = new Parser(xmlString); SecurityElement topElement = p.GetTopElement(); // P is always present String pString = topElement.SearchForTextOfLocalName("P"); if (pString == null) { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "DSA", "P")); } dsaParams.P = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(pString)); // Q is always present String qString = topElement.SearchForTextOfLocalName("Q"); if (qString == null) { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "DSA", "Q")); } dsaParams.Q = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(qString)); // G is always present String gString = topElement.SearchForTextOfLocalName("G"); if (gString == null) { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "DSA", "G")); } dsaParams.G = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(gString)); // Y is always present String yString = topElement.SearchForTextOfLocalName("Y"); if (yString == null) { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "DSA", "Y")); } dsaParams.Y = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(yString)); // J is optional String jString = topElement.SearchForTextOfLocalName("J"); if (jString != null) { dsaParams.J = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(jString)); } // X is optional -- private key if present String xString = topElement.SearchForTextOfLocalName("X"); if (xString != null) { dsaParams.X = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(xString)); } // Seed and PgenCounter are optional as a unit -- both present or both absent String seedString = topElement.SearchForTextOfLocalName("Seed"); String pgenCounterString = topElement.SearchForTextOfLocalName("PgenCounter"); if ((seedString != null) && (pgenCounterString != null)) { dsaParams.Seed = Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(seedString)); dsaParams.Counter = ConvertByteArrayToInt(Convert.FromBase64String(AsymmetricAlgorithm.DiscardWhiteSpaces(pgenCounterString))); } else if ((seedString != null) || (pgenCounterString != null)) { if (seedString == null) { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "DSA", "Seed")); } else { throw new CryptographicException(String.Format(Environment.GetResourceString("Cryptography_InvalidFromXmlString"), "DSA", "PgenCounter")); } } ImportParameters(dsaParams); }
public void SetKey(AsymmetricAlgorithm arg0) { }
public virtual AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) { AsymmetricSignatureFormatter? item = (AsymmetricSignatureFormatter?)CryptoConfig.CreateFromName(FormatterAlgorithm!); item!.SetKey(key); return item; }
private static SafeEcKeyHandle GenerateKeyLazy(AsymmetricAlgorithm owner) => GenerateKeyByKeySize(owner.KeySize);
/// <summary>Creates an instance of the default implementation of an asymmetric algorithm.</summary> /// <returns>A new <see cref="T:System.Security.Cryptography.RSACryptoServiceProvider" /> instance, unless the default settings have been changed with the <cryptoClass> element.</returns> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// </PermissionSet> public static AsymmetricAlgorithm Create() { return(AsymmetricAlgorithm.Create("System.Security.Cryptography.AsymmetricAlgorithm")); }
/// <include file='doc\RSAOAEPKeyExchangeFormatter.uex' path='docs/doc[@for="RSAOAEPKeyExchangeFormatter.RSAOAEPKeyExchangeFormatter1"]/*' /> public RSAOAEPKeyExchangeFormatter(AsymmetricAlgorithm key) { SetKey(key); }
public void SetKey(AsymmetricAlgorithm key) { }
internal static byte[] ExportEncryptedPkcs8PrivateKey( AsymmetricAlgorithm key, ReadOnlySpan <byte> passwordBytes, PbeParameters pbeParameters !!) {
public DSASignatureDeformatter(AsymmetricAlgorithm key) { return(default(DSASignatureDeformatter)); }
/// <summary> /// Initializes a new instance of the <see cref="RsaCryptographicKey" /> class. /// </summary> /// <param name="publicKey">The public key.</param> /// <param name="parameters">The RSA instance, if available.</param> /// <param name="algorithm">The algorithm.</param> internal RsaCryptographicKey(IPublicKey publicKey, RSAParameters parameters, AsymmetricAlgorithm algorithm) { Requires.NotNull(publicKey, "publicKey"); this.publicKey = publicKey.JavaCast<IRSAPublicKey>(); this.parameters = parameters; this.algorithm = algorithm; }