(copied verbatim from http://www.madboa.com/geek/openssl/#encrypt mostly as a mirror if the site ever goes down)
Note: the site has very interesting information on openssl, encryption, keys etc you should definitely check it out
Encryption/Decryption
How do I base64-encode something?
Use the enc -base64 option.
$ openssl enc -base64 -in file.txt
$ openssl enc -base64 -in file.txt -out file.txt.enc
It’s also possible to do a quick command-line encoding of a string value:
$ echo “encode me” | openssl enc -base64 ZW5jb2RlIG1lCg==
Note that echo will silently attach a newline character to your string. Consider using its -n option if you want to avoid that situation, which could be important if you’re trying to encode a password or authentication string.
$ echo -n “encode me” | openssl enc -base64 ZW5jb2RlIG1l
Use the -d (decode) option to reverse the process.
$ echo “ZW5jb2RlIG1lCg==” | openssl enc -base64 -d encode me
How do I simply encrypt a file?
Simple file encryption is probably better done using a tool like GPG. Still, you may have occasion to want to encrypt a file without having to build or use a key/certificate structure. All you want to have to remember is a password. It can nearly be that simple—if you can also remember the cipher you employed for encryption.
To choose a cipher, consult the enc(1) man page. More simply (and perhaps more accurately), you can ask openssl for a list in one of two ways.
$ openssl -h
$ openssl list-cipher-commands
After you choose a cipher, you’ll also have to decide if you want to base64-encode the data. Doing so will mean the encrypted data can be, say, pasted into an email message. Otherwise, the output will be a binary file.
$ openssl enc -aes-256-cbc -salt -in file.txt -out file.enc
$ openssl enc -aes-256-cbc -a -salt -in file.txt -out file.enc
To decrypt file.enc you or the file’s recipient will need to remember the cipher and the passphrase.
$ openssl enc -d -aes-256-cbc -in file.enc
$ openssl enc -d -aes-256-cbc -a -in file.enc
Install Virtualbox’s Guest Additions first.
Virtualbox’s automount is broken. To reliably share folders between the host and the guest operating systems:
- Mark the folders you want to share in the VM’s settings, but don’t choose auto-mount.
- Start the VM.
- Add the following line to /etc/fstab Documents /media/Documents vboxsf uid=1000,gid=1000,nodev,noexec,nosuid,auto,rw 0 0
- reboot for Magic
- Check if the module is being loaded
- blacklist it in /etc/modprobe.d/blacklist.conf by adding the following line to it:
- Update initramfs
If you want to mount your Vbox root partition without using Virtual Box, you might find the following commands useful :
$ sudo apt-get install qemu-kvm # Assumes you use Ubuntu as host $ sudo modprobe nbd $ sudo su
$ qemu-nbd -c /dev/nbd0 /media/Misc/ubuntu10.10-OS.vdi
$ mount /dev/nbd0p1 /mnt
Now you should be able to the see all your files in /mnt.
For fsck :
$ umount /mnt $ fsck /dev/nbd0p1
xrandrTake the top-most value
pactl list sourcesLook for the input source alsa_input and note the source number.
(eg: Source #1)
echo $DISPLAYffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :1 -f pulse -ac 2 -i 1 output.mkv -async 1 -vsync 1video_size- screen resolution, taken from the output of
xrandr framerate- the framerate you want
f- video format. In this case, input format is the
output of the X server (
x11grab) i- The video input, taken from output of
echo $DISPLAY f- Set expected format to be PulseAudio (
pulse) ac- Set the number of audio channels (2)
i- The audio input, taken from output of
pactl - output.mkv
- Output filename
async,vsync- Deprecated options. Added to avoid cluttering output log.
$ ffmpeg -i input.flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3Youtube videos are downloaded as webm. To keep only the audio:
ffmpeg -i in.mp4 -q:a 0 -map a out.mp3I needed to cut a 30 minute interview to only include the parts where Rani Maushi was being interviewed.The better way to encode MP3 is to use -q:a for variable bit rate.
The q option can only be used with libmp3lame and corresponds to the LAME -V option. See Encoding VBR (Variable Bit Rate) mp3 audio: https://trac.ffmpeg.org/wiki/Encode/MP3
ffmpeg solved the problem quickly.
- The introduction is from 00:00 to 02:10, which describes the program
ffmpeg -ss 0 -t 130 -i full_interview.mp3 -c:a copy 01_introduction.mp3
- Rani maushi’s interview starts from 18:35 (1115s) to 24:25 (1465s), when the interview cuts into one of her favorite songs. (Cut the song out)
ffmpeg -ss 1115 -t 350 -i rani_maushi_interview.mp3 -c:a copy 02_interview_part_1.mp3
- Song ends at 27:40 (1660), interview starts again, ends at 29:00 (1740).
ffmpeg -ss 1660 -t 80 -i rani_maushi_interview.mp3 -c:a copy 03_interview_part_2.mp3
- Stitching the 3 parts together:
ffmpeg -f concat -i interview_parts.txt -c copy meghana_chaphalkar_interview.mp3interview_parts.txtwas in the same folder and contained the following:file 01_introduction.mp3 file 02_interview_part_1.mp3 file 03_interview_part_2.mp3
- Resources:
- https://stackoverflow.com/a/65099636/137430 is a great answer explaining all the moving parts
- https://stackoverflow.com/a/63431041/137430 explains when
-c:a copyshould be used and when it should be not. (it should be used when you don’t need to recode the stream – input and output formats are the same) - https://superuser.com/a/1215832/69800 explains how to concatenate different mp3 files
- https://stackoverflow.com/q/38996925/137430 Question and answers explain the nuances of using the
concatdemuxer. Related: https://trac.ffmpeg.org/wiki/Concatenate - https://stackoverflow.com/questions/40602706/batch-reduce-bitrate-and-size-of-mp3-audio-files-with-ffmpeg#comment115596578_40668427 on reducing the bitrate (and therefore the size) of the output file
ffmpeg -f concat -i parts.txt -c copy new_file.mp3interview_parts.txtwas in the same folder and contained the following:file 01_part.mp3 file 02_part.mp3 file 03_part.mp3
dalai llama on my machine, and I want to share the recording, but since the llama is slow, it takes a long time to generate the data. I would rather cut out the empty parts of the video. To do this, I will wait for dalai to start producing data and then cut out 5 seconds after every second to speed up the demo.
This command speeds up the video 8 times.
ffmpeg -ss 13 -i llama_in_action.mov -filter:v "setpts=0.125*PTS" -c:a aac -c:v libx264 02_llama_in_action.mov
To slow it down 4 times, use "setpts=4*PTS"
ffmpeg -i video.mp4 -vf scale=500:-1 -ss 30 -t 10 -r 10 image.gif
vf: applies a video filter, in this casescale. Here we are scaling the width to 500 and the height accordingly.ss: starting point in the video, in secondst: duration of gif, in secondsr: frame rate to use. here, 10 fps
ffmpeg -i 1.jpg -vf scale=480:-1 1_480.jpg
ffmpeg -i 1.jpg -vf -qscale:v 5 1_qscale5.jpg
$ sudo nmap -sn 192.168.1.0/24- Use poppler’s pdftoppm
pdftoppm -png file.pdf > file.png
- In
.mbsyncrc, setExpungetoBothfor your email channels. This propagates the deletions to the mail servers when mbsync runs a sync operation. - List all the deleted emails
notmuch search --output=files --exclude=false tag:deleted - Add the correct
maildirflag (Tto indicate Trash) to the end of the maildir files where it is missing. Ensure that the maildir file ends in the correct flags.- Flags are as follows
T: TrashD: DraftS: SeenP: Passed (Forwarded)R: Replied
- File should end in
2,<flags>(eg:2,ST).
- Flags are as follows
- Make sure that you are only dealing with maildir files with the
correct flag information.
notmuch search --output=files --exclude=false tag:deleted | grep "2,ST$" | wc -l
- TODO : Add a step here to add the T flag to the files if it is missing.
- Sync the files to the remote mailbox using mbsync, as you would
normally do. (eg:
/usr/local/bin/mbsync gmail;)- This will mark the files for deletion on the remote mailbox.
- Delete the files from the local mailbox
notmuch search --output=files --exclude=false tag:deleted | grep "2,ST$" | xargs rm