Beispiel #1
0
 public static void Encrypt(bool usePassword, string keyfile, string privateKey, string publicKey, string[] filePaths)
 {
     if (usePassword || !string.IsNullOrEmpty(keyfile))
     {
         char[] password = Array.Empty <char>();
         if (usePassword)
         {
             password = PasswordPrompt.EnterNewPassword();
         }
         FileEncryptionWithPassword(password, keyfile, filePaths);
     }
     else if (!string.IsNullOrEmpty(publicKey) && !string.IsNullOrEmpty(privateKey))
     {
         if (publicKey.EndsWith(Constants.PublicKeyExtension))
         {
             FileEncryptionWithPublicKey(privateKey, publicKey, filePaths);
             return;
         }
         // Use private key string
         FileEncryptionWithPublicKey(privateKey, publicKey.ToCharArray(), filePaths);
     }
     else if (!string.IsNullOrEmpty(privateKey))
     {
         FileEncryptionWithPrivateKey(privateKey, filePaths);
     }
     else
     {
         DisplayMessage.Error("Please either specify a (password and/or keyfile), (private key and public key), or private key.");
     }
 }
Beispiel #2
0
 public static (string publicKey, string privateKey) GenerateSigningKeyPair()
 {
     char[] password      = PasswordPrompt.EnterNewPassword();
     byte[] passwordBytes = Password.Hash(password);
     using var keyPair = PublicKeyAuth.GenerateKeyPair();
     byte[] publicKey           = Utilities.ConcatArrays(Constants.Ed25519KeyHeader, keyPair.PublicKey);
     byte[] encryptedPrivateKey = PrivateKey.Encrypt(passwordBytes, keyPair.PrivateKey, Constants.Ed25519KeyHeader);
     return(ConvertKeys(publicKey, encryptedPrivateKey));
 }
Beispiel #3
0
 public static (string publicKey, string privateKey) GenerateEncryptionKeyPair()
 {
     char[] password      = PasswordPrompt.EnterNewPassword();
     byte[] passwordBytes = Password.Hash(password);
     using var keyPair = PublicKeyBox.GenerateKeyPair();
     byte[] publicKey           = Arrays.Concat(Constants.Curve25519KeyHeader, keyPair.PublicKey);
     byte[] encryptedPrivateKey = PrivateKey.Encrypt(passwordBytes, Constants.Curve25519KeyHeader, keyPair.PrivateKey);
     return(ConvertKeys(publicKey, encryptedPrivateKey));
 }
Beispiel #4
0
 public static byte[] Decrypt(byte[] privateKey)
 {
     try
     {
         char[] password      = PasswordPrompt.EnterYourPassword();
         byte[] passwordBytes = Password.Hash(password);
         return(Decrypt(passwordBytes, privateKey));
     }
     catch (CryptographicException)
     {
         DisplayMessage.Error("Incorrect password or the private key has been tampered with.");
         return(null);
     }
 }