Discuss this help topic in SecureBlackbox Forum

Encrypt a file with a password

Password-based encryption is a convenient way of exchanging information securely with someone who does not have an OpenPGP key pair. SecureBlackbox supports such encryption through a dedicated encryption mode of TElPGPWriter component.

  1. To start with, create an instance of TElPGPWriter class:
    TElPGPWriter writer = new TElPGPWriter();
    
  2. Set its EncryptionType property to TSBPGPEncryptionType.etPassphrase:
    pgpWriter.EncryptionType = SBPGP.TSBPGPEncryptionType.etPassphrase;
    
  3. Add all the passwords you wish to be able to decrypt the protected object to the Passphrases list. You can add as many as you like:
    pgpWriter.Passphrases.Add("pa$$w0rd");
    pgpWriter.Passphrases.Add("qwerty");
    
  4. Provide the source filename (doesn't need to be the real file name) and the encryption date:
    pgpWriter.Filename = "picture.jpg";
    pgpWriter.Timestamp = DateTime.UtcNow;
    
    Note: an empty string assigned to the Filename property will make the components create a for-your-eyes-only file, which won't be decrypted to a persistent media.
  5. Tune-up encryption settings:
    pgpWriter.SymmetricKeyAlgorithm = SBPGPConstants.Unit.SB_PGP_ALGORITHM_SK_AES256;
    
    Note: in default configuration, TElPGPWriter comes with its own pre-defined encryption settings (CAST5 with 128 bit key, on the date of creation of this article).
  6. Optionally tune-up supplementary options, such as armouring:
    pgpWriter.Armor = true;
    pgpWriter.Compress = true;
    
  7. Call EncryptFile() method:
    pgpWriter.EncryptFile("picture.jpg", "picture.jpg.pgp");
    

How To articles about file encryption and signing with OpenPGP

Discuss this help topic in SecureBlackbox Forum