PGP Encryption Fails on Large Files - encryption

I'm in this weird situation.
I'm trying to encrypt this 11GB which has ~42 Million rows in it using PGP with RSA/Armored Public Key.
Here are the commands I used:
Import Key ->
gpg --import ~/underwood/keys/my_pub_4096_RSA_key.asc
PGP Encryption -
gpg -r "underwood#publickey.com" -o /usr/local/encrrypted-file/encrypted-11GB-file.txt.pgp
--armor --encrypt /usr/local/file-to-encrrypt/this-is-a-11GB-file.txt
`
Issue :
The file size of /usr/local/encrrypted-file/encrypted-11GB-file.txt.pgp is 4GB and row count is only 8M. I'm not sure what happened here. The command completed successfully after 3min without errors.
Question:
How do I further investigate this issue ?
Is there a cap on gpg command on file size ? Because this command workds perfectly fine with 500MB file.
How do I achieve full encryption on 11GB file ?
One solution I can think on top of my head is to chunk the 11GB in 500MB files and do this. But the problem here, I'm not allowed to chunk the file.
Please let me know if there is a better solution to this.

See unix split function to split a binary file into pieces.

Related

Encrypt zip file in folder with PGP

I have been testing with PGP command line to create a batch file that encrypts all zip files in a folder
So far I have tried
GPG -e -r username c:\foldername*.zip
But when I run the bat file nothing happens.
Do I need the path to where PGP is installed adding?
I would also like to delete the zip once it’s encrypted and on a previous batch file used -SDEL, will this work here
Thanks
gpg doesn't seem to work file wildcards. You should use for cycle, see this answer for the examples: How to do something to each file in a directory with a batch script

GnuPG decrypt multiple files

I need to decrypt multiple files, in my batch file I have
--decrypt-files c:\PGP\unprocessed\*.pgp
but my script doesn't work. I receive
gpg: can't open c:\PGP\unprocessed*.pgp
instead, and I don't know why. --decrypt c:\PGP\unprocessed\filename.pgp works fine.
Another question is how to use --output when decrypting multiple files? Because when I try to combine two commands I receive an error message indicating that output doesn't work with this command.
For multiple files, the important are options
--multifile --decrypt
Work on CMD:
gpg --pinentry-mode=loopback --passphrase-file "C:\key.txt" --batch --ignore-mdc-error --skip-verify --multifile --decrypt "C:\\files\*.pgp"
The Windows command line is very limited in different ways, one is the lack of reasonable globbing: it does not expand ...\*.pgp to the actual files in that folder. Use a more capable shell (PowerShell, or install one of the shells from the unix world like bash using for example cygwin). Solutions for sticking with cmd.exe would be to pass the filenames through stdin (something like dir *.pgp | gpg --decrypt-files or writing a loop over all *.pgp files and decrypt them individually.
Latter would also help with the second part of your problem: --output can only define a single output; thus it does not work when multiple input files are passed.

Compress a file with password- encryption not supported

I am going to compress some .csv file in one file, but I have to set password for this.
I have used zip -P password file.zip myfiles
but it gives me an error...
zip error: Invalid command arguments (encryption not supported)
I am working on Solaris machine.
Could someone help me about this?
I found the way
7z a -p[password] -r Fdirectory.7z /path/to/F

Reading a vi encrypted file programmatically

I have a vi encrypted text file for storing the login details of DB. Now in my shell script I wanted to get the content say grep DB_NAME login_details.txt.
How do I pass the vi encryption password to the grep command ?
I believe everything is explained on this vim wikia page: http://vim.wikia.com/wiki/Encryption.
Read it whole (it warns you about when the file is actually encrypted, that the viminfo should be unset, etc...)
Especially is show how yo know the encryption used with :setlocal cm? ("show encryption method for the current file") and how to change it with :setlocal cm=... too.
But this is not interactive "per say" ... but you can use command line equivalent to have vim do this from the command line (which then can be used in a script), adding commands to just print the relevant line(s)
If you meant vi instead of vim, you need to specify which OS it is on, and look at vi encryption: what algorithm has been used?
This page shows 2 solutions depending on the type of OS used (And I'm quite sure there is a way to do the equivalent "on the fly", ie without having the decrypted file on disk... look for mcrypt -d --force ... (without specifying a destination file so it has to go to stdout. You need --force otherwise mcrypt refuses to output to stdout)
thing=$(echo '1,$'|vim --cmd "set key=${password}" ${filename} -es|grep needle)
This will load vim with the password and file read in from variables that you set previously somehow, and then dump the entire file contents to stdout, and then grep for the string "needle" and if it exists, it will be stored as the $thing variable.
This example is a bad practice, you should use existing tooling to accomplish secure decryption.

Writing to Tape Drive Multiple Times using tar command

I am using the command
tar -cvfE $TAPE_DRIVE $BACKUP_FILE
to write to tape for the first time. It works like a charm.
BUT, when there is already a file in the tape (older backup) I use the command
tar -rvfE $TAPE_DRIVE $BACKUP_FILE
which disappoints every time.
There is enough space on the tape (1.3TB).
I am only writing 80-90GB files at a time.
The tape is mounted locally.
After failing to write to tape if I try to list files on tape, i get the old (first) file that I wrote to it.
Is there any other command I should be using?
Apparently the native tar commands is not perfect and has bugs. It is recommended that using -i (ignore directory checksum errors) flag will resolve this but it did not in my case.
Using GNU tar solved my problem. Simply use gtar instead of tar and it works like a charm.
So the commands are like
gtar -cvf $TAPE_DRIVE $BACKUP_FILE
and
gtar -rvf $TAPE_DRIVE $BACKUP_FILE

Resources