Ejemplo n.º 1
0
        public static void RecoverPublicKey(string privateKeyPath)
        {
            bool validUserInput = FilePathValidation.RecoverPublicKey(privateKeyPath);

            if (!validUserInput)
            {
                return;
            }
            byte[] privateKey = AsymmetricKeyValidation.GetPrivateKeyFromFile(privateKeyPath);
            if (privateKey == null)
            {
                return;
            }
            privateKey = PrivateKey.Decrypt(privateKey);
            if (privateKey == null)
            {
                return;
            }
            byte[] publicKey = privateKey.Length switch
            {
                Constants.EncryptionKeyLength => AsymmetricKeys.GetCurve25519PublicKey(privateKey),
                _ => AsymmetricKeys.GetEd25519PublicKey(privateKey),
            };
            Console.WriteLine($"Public key: {Convert.ToBase64String(publicKey)}");
        }
Ejemplo n.º 2
0
        public static void Sign(string privateKeyPath, string comment, bool preHash, string signatureFilePath, string[] filePaths)
        {
            bool validUserInput = SigningValidation.Sign(privateKeyPath, comment, signatureFilePath, filePaths);

            if (!validUserInput)
            {
                return;
            }
            byte[] privateKey = AsymmetricKeyValidation.SigningPrivateKeyFile(privateKeyPath);
            if (privateKey == null)
            {
                return;
            }
            FileSigning.SignEachFile(filePaths, signatureFilePath, comment, preHash, privateKey);
        }
Ejemplo n.º 3
0
        private static void FileDecryptionWithPrivateKey(string privateKeyPath, string[] filePaths)
        {
            bool validUserInput = FileEncryptionValidation.FileEncryptionWithPrivateKey(privateKeyPath, filePaths);

            if (!validUserInput)
            {
                return;
            }
            byte[] privateKey = AsymmetricKeyValidation.EncryptionPrivateKeyFile(privateKeyPath);
            if (privateKey == null)
            {
                return;
            }
            FileDecryption.DecryptEachFileWithPrivateKey(filePaths, privateKey);
        }
Ejemplo n.º 4
0
        private static void FileEncryptionWithPublicKey(string senderPrivateKeyPath, char[] recipientPublicKeyString, string[] filePaths)
        {
            bool validUserInput = FileEncryptionValidation.FileEncryptionWithPublicKey(senderPrivateKeyPath, recipientPublicKeyString, filePaths);

            if (!validUserInput)
            {
                return;
            }
            byte[] senderPrivateKey = AsymmetricKeyValidation.EncryptionPrivateKeyFile(senderPrivateKeyPath);
            if (senderPrivateKey == null)
            {
                return;
            }
            byte[] recipientPublicKey = AsymmetricKeyValidation.EncryptionPublicKeyString(recipientPublicKeyString);
            if (recipientPublicKey == null)
            {
                return;
            }
            FileEncryption.EncryptEachFileWithPublicKey(filePaths, senderPrivateKey, recipientPublicKey);
        }
Ejemplo n.º 5
0
        private static void VerifySignature(string publicKeyPath, string signatureFilePath, string[] filePaths)
        {
            bool validUserInput = SigningValidation.Verify(publicKeyPath, signatureFilePath, filePaths);

            if (!validUserInput)
            {
                return;
            }
            signatureFilePath = FilePathValidation.GetSignatureFilePath(signatureFilePath, filePaths);
            bool validSignatureFile = SigningValidation.SignatureFile(signatureFilePath);

            if (!validSignatureFile)
            {
                return;
            }
            byte[] publicKey = AsymmetricKeyValidation.SigningPublicKeyFile(publicKeyPath);
            if (publicKey == null)
            {
                return;
            }
            FileSigning.VerifyFile(signatureFilePath, filePaths[0], publicKey);
        }
Ejemplo n.º 6
0
        private static void VerifySignature(char[] encodedPublicKey, string[] filePaths)
        {
            bool validUserInput = SigningValidation.Verify(encodedPublicKey, filePaths);

            if (!validUserInput)
            {
                return;
            }
            string signatureFilePath  = SigningValidation.GetSignatureFilePath(ref filePaths);
            bool   validSignatureFile = SigningValidation.SignatureFile(signatureFilePath, filePaths);

            if (!validSignatureFile)
            {
                return;
            }
            byte[] publicKey = AsymmetricKeyValidation.SigningPublicKeyString(encodedPublicKey);
            if (publicKey == null)
            {
                return;
            }
            FileSigning.VerifyFile(publicKey, signatureFilePath, filePaths[0]);
        }