module-ballerina-crypto icon indicating copy to clipboard operation
module-ballerina-crypto copied to clipboard

Add support for PGP encryption/decryption with files

Open TharmiganK opened this issue 4 months ago • 3 comments

Purpose

$Subject

Fixes: https://github.com/ballerina-platform/ballerina-library/issues/7064

With this PR, two new functionalities are added to the crypto module:

  • encryptPgpAsFile: Read the content from a file, encrypt with PGP and write the encrypted file in the output path
  • decryptPgpAsFile: Read the content from an PGP encrypted file, decrypt with PGP and write the decrypted file in the output path

With this new APIs, large files can be encrypted/decrypted with PGP, without loading the entire content into the memory.

Find the following results with large files(the files are generated by empty characters):

File Size Encryption duration Encryption max memory usage Decryption(from the encrypted file) duration Decryption max memory usage
1 GB 7.23 seconds 46 MB 4.22 seconds 46 MB
5 GB 38.13 seconds 57 MB 20 seconds 46 MB

Examples

  • Encryption sample:
check crypto:encryptPgpAsFile(inputPath, publicKeyPath, outputPath);
  • Decryption sample:
check crypto:decryptPgpAsFile(inputFilePath, privateKeyPath, passPhraseInBytes, outputFilePath);

Checklist

  • [x] Linked to an issue
  • [x] Updated the changelog
  • [x] Added tests
  • [x] Updated the spec
  • [x] Checked native-image compatibility

TharmiganK avatar Oct 02 '24 09:10 TharmiganK