Exemplo n.º 1
0
        public static void Write_Signature(string file, string signature, int RSAKeyLength, HashingMode mode)
        {
            var streamWriter = new StreamWriter(Program.Direktorij + file);

            streamWriter.WriteLine("---BEGIN OS 2 CRYPTO DATA---");
            streamWriter.WriteLine();
            streamWriter.WriteLine("Description");
            streamWriter.WriteLine("    Singature");
            streamWriter.WriteLine();
            streamWriter.WriteLine("File name:");

            var breadCrumbs = file.Split('\\');

            streamWriter.WriteLine("    " + breadCrumbs[breadCrumbs.Length - 1]);
            streamWriter.WriteLine();

            streamWriter.WriteLine("Method:");
            int hashLenght;

            if (mode == HashingMode.SHA_1)
            {
                streamWriter.WriteLine("    SHA-1");
                hashLenght = 160;
            }
            else if (mode == HashingMode.SHA_2_256)
            {
                streamWriter.WriteLine("    SHA-2 (256)");
                hashLenght = 256;
            }
            else
            {
                streamWriter.WriteLine("    SHA-2 (512)");
                hashLenght = 512;
            }
            streamWriter.WriteLine("    RSA");
            streamWriter.WriteLine();
            streamWriter.WriteLine("Key length:");
            streamWriter.WriteLine("    " + HelperFunctions.FromIntToHex(hashLenght));
            streamWriter.WriteLine("    " + HelperFunctions.FromIntToHex(RSAKeyLength));
            streamWriter.WriteLine();
            streamWriter.WriteLine("Signature:");

            var NumLines = (double)signature.Length / 60;

            if (Math.Truncate(NumLines) < NumLines)
            {
                NumLines++;
            }

            for (var i = 0; i < Math.Truncate(NumLines); i++)
            {
                if (signature.Length - i * 60 < 60)
                {
                    streamWriter.WriteLine("    " + signature.Substring(i * 60, signature.Length - i * 60));
                }
                else
                {
                    streamWriter.WriteLine("    " + signature.Substring(i * 60, 60));
                }
            }

            streamWriter.WriteLine();
            streamWriter.WriteLine("---END OS2 CRYPTO DATA---");
            streamWriter.Close();
        }
Exemplo n.º 2
0
        public static void Write_Envelope(string file, HelperClasses.Envelope envelope, int symetricAlgorithmKeyLenght, int RSAKeyLength, SymetricAlgorithm algorithm)
        {
            var streamWriter = new StreamWriter(Program.Direktorij + file);

            streamWriter.WriteLine("---BEGIN OS 2 CRYPTO DATA---");
            streamWriter.WriteLine();
            streamWriter.WriteLine("Description");
            streamWriter.WriteLine("    Envelope");
            streamWriter.WriteLine();
            streamWriter.WriteLine("File name:");

            var breadCrumbs = file.Split('\\');

            streamWriter.WriteLine("    " + breadCrumbs[breadCrumbs.Length - 1]);
            streamWriter.WriteLine();

            streamWriter.WriteLine("Method:");
            streamWriter.WriteLine(algorithm == SymetricAlgorithm.AES ? "    AES" : "    3DES");
            streamWriter.WriteLine("    RSA");
            streamWriter.WriteLine();
            streamWriter.WriteLine("Key length:");
            streamWriter.WriteLine("    " + HelperFunctions.FromIntToHex(symetricAlgorithmKeyLenght));
            streamWriter.WriteLine("    " + HelperFunctions.FromIntToHex(RSAKeyLength));
            streamWriter.WriteLine();
            streamWriter.WriteLine("Envelope data:");

            var NumLines = (double)envelope.Data.Length / 60;

            if (Math.Truncate(NumLines) < NumLines)
            {
                NumLines++;
            }

            for (var i = 0; i < Math.Truncate(NumLines); i++)
            {
                if (envelope.Data.Length - i * 60 < 60)
                {
                    streamWriter.WriteLine("    " + envelope.Data.Substring(i * 60, envelope.Data.Length - i * 60));
                }
                else
                {
                    streamWriter.WriteLine("    " + envelope.Data.Substring(i * 60, 60));
                }
            }

            streamWriter.WriteLine();
            streamWriter.WriteLine("Envelope crypt key:");

            NumLines = (double)envelope.Key.Length / 60;

            if (Math.Truncate(NumLines) < NumLines)
            {
                NumLines++;
            }

            for (var i = 0; i < Math.Truncate(NumLines); i++)
            {
                if (envelope.Key.Length - i * 60 < 60)
                {
                    streamWriter.WriteLine("    " + envelope.Key.Substring(i * 60, envelope.Key.Length - i * 60));
                }
                else
                {
                    streamWriter.WriteLine("    " + envelope.Key.Substring(i * 60, 60));
                }
            }

            streamWriter.WriteLine();
            streamWriter.WriteLine("---END OS2 CRYPTO DATA---");
            streamWriter.Close();
        }