FromXmlString() public method

public FromXmlString ( string xmlString ) : void
xmlString string
return void
Beispiel #1
0
        /// <summary>
        /// Signiert ein Xml-Document.
        /// </summary>
        /// <param name="xDoc">Das Dokument welches die Daten enthält die signiert werden sollen.</param>
        /// <param name="privateKey">Der private Schlüssel.</param>
        /// <returns>Gibt ein Xml Element mit den Signierten daten zurück.</returns>
        public static XmlElement SignXmlDocument(XmlDocument xDoc, string privateKey)
        {
            var signedXml = new SignedXml();

            System.Security.Cryptography.RSA pvk = System.Security.Cryptography.RSA.Create();
            pvk.FromXmlString(privateKey);
            signedXml.SigningKey = pvk;

            var dataObject = new DataObject();

            dataObject.Id   = "content";
            dataObject.Data = xDoc.ChildNodes;

            signedXml.AddObject(dataObject);

            var reference = new Reference();

            reference.Uri = "#content";

            signedXml.AddReference(reference);

            var keyinfo = new KeyInfo();

            keyinfo.AddClause(new RSAKeyValue(pvk));
            signedXml.KeyInfo = keyinfo;

            signedXml.ComputeSignature();

            return(signedXml.GetXml());
        }
        public S3Storage()
        {
            const string filename = "keyxml.pk";
            var path = WebServerPathUtils.GetPathTo(Path.Combine("bin", filename));
            var f = new FileInfo(path);

            if (f.Exists)
            {
                using (var file = f.OpenRead())
                {
                    var keyString = new StreamReader(file).ReadToEnd();
                    _algorithm = RSA.Create();
                    _algorithm.FromXmlString(keyString);

                    var encryptionMaterials = new EncryptionMaterials(_algorithm);
                    try
                    {
                        _client = new AmazonS3EncryptionClient(encryptionMaterials);

                        var bucket = new S3DirectoryInfo(_client, PdfDocumentsBucketName);
                        if (!bucket.Exists)
                        {
                            bucket.Create();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Unable to initialize S3 client\n" + ex);
                    }
                }
            }
        }
Beispiel #3
0
        public void LoadKey() {
            string import = "";
            using(StreamReader streamReader = new StreamReader(KeyStore))
                import = streamReader.ReadToEnd();

            publicKey = new RSACryptoServiceProvider();
            publicKey.FromXmlString(import);

            AsymmetricCipherKeyPair cipherKeyPair = DotNetUtilities.GetRsaKeyPair(publicKey.ExportParameters(true));
            privateKey = cipherKeyPair.Private;
            publicKey.ImportParameters(publicKey.ExportParameters(false));
            
            Directory.CreateDirectory(DestDir);
        }
Beispiel #4
0
        /// <summary>
        /// Signiert einen Text mit dem angegebenen privaten Schlüssel.
        /// </summary>
        /// <param name="textToSign">Der zusignierende Text.</param>
        /// <param name="privateKey">Der private Schlüssel.</param>
        /// <returns></returns>
        public static string Sign(string textToSign, string privateKey)
        {
            //Initialisieren der Provider
            var rsaCryptoServiceProvider = new RSACryptoServiceProvider();
            var rsaFormatter             = new RSAPKCS1SignatureFormatter(rsaCryptoServiceProvider);

            System.Security.Cryptography.RSA rsa = System.Security.Cryptography.RSA.Create();
            var encoding = new ASCIIEncoding();
            var sha1     = new SHA1Managed();

            //Zuweisen des Hashalgorithmus und des privaten Schlüssels
            rsaFormatter.SetHashAlgorithm("SHA1");
            rsa.FromXmlString(privateKey);
            rsaFormatter.SetKey(rsa);

            //String nach Byte[] Konvertieren und die Signatur erstellen
            byte[] valueToHash = encoding.GetBytes(textToSign);
            byte[] signedValue = rsaFormatter.CreateSignature(sha1.ComputeHash(valueToHash));

            return(Convert.ToBase64String(signedValue));
        }
Beispiel #5
0
        /// <summary>
        /// Validiert einen signierten String
        /// </summary>
        /// <param name="textToValidate">Der unsignierte Text welcher mit der Signatur überprüft werden soll.</param>
        /// <param name="signToValidate">Die Signatur des Textes.</param>
        /// <param name="publicKey">Der öffentliche Schlüssel.</param>
        /// <returns></returns>
        public static bool validateSign(string textToValidate, string signToValidate, string publicKey)
        {
            //Initialisieren der Provider
            var rsacryptoprov  = new RSACryptoServiceProvider();
            var rsaDeFormatter = new RSAPKCS1SignatureDeformatter(rsacryptoprov);

            System.Security.Cryptography.RSA rsa = System.Security.Cryptography.RSA.Create();
            var sha1     = new SHA1Managed();
            var encoding = new ASCIIEncoding();

            //Zuweisen des Hashalgorithmus und des öffentlichen Schlüssels
            rsaDeFormatter.SetHashAlgorithm("SHA1");
            rsa.FromXmlString(publicKey);
            rsaDeFormatter.SetKey(rsa);

            //String nach Byte[]
            byte[] hashed_value = encoding.GetBytes(textToValidate);
            byte[] signed_value = Convert.FromBase64String(signToValidate);

            //Signatur validieren und wert zurückgeben true/false
            return(rsaDeFormatter.VerifySignature(sha1.ComputeHash(hashed_value), signed_value));
        }
Beispiel #6
0
 public void LoadXml(string xmlString)
 {
     rsa.FromXmlString(xmlString);
 }
Beispiel #7
0
 public override void FromXmlString(string xmlString) => _impl.FromXmlString(xmlString);
Beispiel #8
0
    /// <summary>
    /// RSA加载JAVA  publicJavaKey
    /// </summary>
    /// <param name="privateKey">java提供的第三方公钥</param>
    /// <returns></returns>
    public static void FromPublicKeyJavaString(this System.Security.Cryptography.RSA rsa, string publicJavaKey)
    {
        string xmlpublicKey = rsa.ConvertToXmlPublicJavaKey(publicJavaKey);

        rsa.FromXmlString(xmlpublicKey);
    }
        /// <summary>
        /// Erzeugt eine neue Instanz der XmlSignature-Klasse
        /// </summary>
        /// <param name="xmlRsaKey">RSA key(s)</param>
        public XmlRsaSignature(string xmlRsaKey)
        {
            rsa = RSA.Create();

            rsa.FromXmlString(xmlRsaKey);
        }