Esempio n. 1
0
        public static void CreateDigitalSeal(string inputFile, string RSApublicReciever, string RSAprivateSender, string envelopeFile, string signatureFile, EncryptionMode encryptionMode, HashingMode hashingMode, SymetricAlgorithm algorithm, KeySize keySize)
        {
            DigitalEnvelope.CreateDigitalEnvelope(inputFile, RSApublicReciever, envelopeFile, encryptionMode, algorithm, keySize);

            var envelope = FileManager.Read_Envelope(envelopeFile);

            var hash = SHA.Hash(envelope.Data + envelope.Key, hashingMode);

            DigitalSignature.CreateDigitalSignature_FromString(hash, RSAprivateSender, signatureFile, hashingMode);
        }
Esempio n. 2
0
        public static void CheckDigitalSeal(string outputFile, string RSApublicSender, string RSAprivateReciever, string envelopeFile, string signatureFile, TextBox sealCheck, EncryptionMode encryptionMode, HashingMode hashingMode, SymetricAlgorithm algorithm)
        {
            DigitalEnvelope.OpenDigitalEnvelope(envelopeFile, RSAprivateReciever, outputFile, encryptionMode, algorithm);

            var envelope = FileManager.Read_Envelope(envelopeFile);

            var hash = SHA.Hash(envelope.Data + envelope.Key, hashingMode);

            DigitalSignature.CheckDigitalSignature_FromString(hash, signatureFile, RSApublicSender, sealCheck, hashingMode);
        }
        public static void CheckDigitalSignature_FromString(string text, string signatureFile, string RSApublicKeyFile, TextBox outputTextBox, HashingMode mode)
        {
            var signature = FileManager.Read_Signature(signatureFile);

            var publicKey      = FileManager.Read_RSAKey(RSApublicKeyFile);
            var signatureBytes = HelperFunctions.FromHexToByte(signature);

            var decoded = RSA.Decrypt(Convert.ToBase64String(signatureBytes), publicKey.Modulus, publicKey.Exponent);
            var hash    = SHA.Hash(text, mode);

            outputTextBox.Text = hash == decoded ? "Potpis je valjan!" : "Potpis nije valjan!";
        }
        public static void CreateDigitalSignature_FromString(string plainText, string RSAprivateKeyFile, string outputFile, HashingMode mode)
        {
            var hash = SHA.Hash(plainText, mode);

            var privateKey = FileManager.Read_RSAKey(RSAprivateKeyFile);
            var signature  = RSA.Encrypt(hash, privateKey.Modulus, privateKey.Exponent);

            var signatureBytes = Convert.FromBase64String(signature);

            signature = HelperFunctions.FromByteToHex(signatureBytes);

            FileManager.Write_Signature(outputFile, signature, privateKey.Modulus.Length * 4, mode);
        }