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)}"); }
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); }
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); }
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); }
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); }
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]); }