static private GetNamedParam ( string xml, string param ) : byte[] | ||
xml | string | |
param | string | |
Résultat | byte[] |
/// <summary>Initializes an <see cref="T:System.Security.Cryptography.RSA" /> object from the key information from an XML string.</summary> /// <param name="xmlString">The XML string containing <see cref="T:System.Security.Cryptography.RSA" /> key information. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="xmlString" /> parameter is null. </exception> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The format of the <paramref name="xmlString" /> parameter is not valid. </exception> public override void FromXmlString(string xmlString) { if (xmlString == null) { throw new ArgumentNullException("xmlString"); } RSAParameters parameters = default(RSAParameters); try { parameters.P = AsymmetricAlgorithm.GetNamedParam(xmlString, "P"); parameters.Q = AsymmetricAlgorithm.GetNamedParam(xmlString, "Q"); parameters.D = AsymmetricAlgorithm.GetNamedParam(xmlString, "D"); parameters.DP = AsymmetricAlgorithm.GetNamedParam(xmlString, "DP"); parameters.DQ = AsymmetricAlgorithm.GetNamedParam(xmlString, "DQ"); parameters.InverseQ = AsymmetricAlgorithm.GetNamedParam(xmlString, "InverseQ"); parameters.Exponent = AsymmetricAlgorithm.GetNamedParam(xmlString, "Exponent"); parameters.Modulus = AsymmetricAlgorithm.GetNamedParam(xmlString, "Modulus"); this.ImportParameters(parameters); } catch (Exception inner) { this.ZeroizePrivateKey(parameters); throw new CryptographicException(Locale.GetText("Couldn't decode XML"), inner); } finally { this.ZeroizePrivateKey(parameters); } }
/// <summary>Reconstructs a <see cref="T:System.Security.Cryptography.DSA" /> object from an XML string.</summary> /// <param name="xmlString">The XML string to use to reconstruct the <see cref="T:System.Security.Cryptography.DSA" /> object. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="xmlString" /> parameter is null. </exception> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The format of the <paramref name="xmlString" /> parameter is not valid. </exception> public override void FromXmlString(string xmlString) { if (xmlString == null) { throw new ArgumentNullException("xmlString"); } DSAParameters parameters = default(DSAParameters); try { parameters.P = AsymmetricAlgorithm.GetNamedParam(xmlString, "P"); parameters.Q = AsymmetricAlgorithm.GetNamedParam(xmlString, "Q"); parameters.G = AsymmetricAlgorithm.GetNamedParam(xmlString, "G"); parameters.J = AsymmetricAlgorithm.GetNamedParam(xmlString, "J"); parameters.Y = AsymmetricAlgorithm.GetNamedParam(xmlString, "Y"); parameters.X = AsymmetricAlgorithm.GetNamedParam(xmlString, "X"); parameters.Seed = AsymmetricAlgorithm.GetNamedParam(xmlString, "Seed"); byte[] namedParam = AsymmetricAlgorithm.GetNamedParam(xmlString, "PgenCounter"); if (namedParam != null) { byte[] array = new byte[4]; Buffer.BlockCopy(namedParam, 0, array, 0, namedParam.Length); parameters.Counter = BitConverterLE.ToInt32(array, 0); } this.ImportParameters(parameters); } catch { this.ZeroizePrivateKey(parameters); throw; } finally { this.ZeroizePrivateKey(parameters); } }