<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=4059&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / openssl file encryption scripts]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=4059</link>
		<description><![CDATA[The most recent posts in openssl file encryption scripts.]]></description>
		<lastBuildDate>Sat, 16 Jan 2021 11:24:38 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26816#p26816</link>
			<description><![CDATA[<div class="quotebox"><cite>Head_on_a_Stick wrote:</cite><blockquote><div><div class="quotebox"><cite>dice wrote:</cite><blockquote><div><p>i still need to figure out how to treat file extensions in and out hence trying to use <span class="bbc">${@%.*}&quot;</span> which will probably work in my shell as i think sh is linked to bash in devuan?</p></div></blockquote></div><p>No, /bin/sh is linked to dash in Devuan. If you want to use bashisms then don&#039;t use a /bin/sh shebang. Fortunately though the <span class="bbc">${parameter%word}</span> expansion is POSIX compliant — see section 2.6.2 of the <a href="https://pubs.opengroup.org/onlinepubs/007904875/utilities/xcu_chap02.html" rel="nofollow">official specification</a>.</p><div class="quotebox"><cite>dice wrote:</cite><blockquote><div><p>This uses secure-delete</p></div></blockquote></div><p>Note that secure-delete is not guaranteed to completely delete files stored on a solid state device thanks to wear-levelling and&#160; over-provisioning. TRIM can help with the former (eventually) but not the latter.</p></div></blockquote></div><p>ok thanks. </p><p>I was reading the faq at cryptsetup gitlab today and mentioned something similar to ssd drives. </p><p><a href="https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions" rel="nofollow">https://gitlab.com/cryptsetup/cryptsetu … dQuestions</a></p><div class="quotebox"><blockquote><div><p>Also note that SSDs and also some HDDs (SMR and hybrid HDDs, for<br />example) may not actually overwrite the header and only do that an<br />unspecified and possibly very long time later.&#160; The only way to be sure<br />there is physical destruction.&#160; If the situation permits, do both<br />overwrite and physical destruction.<br />If you have time, overwrite the whole drive with a single pass of random<br />data.&#160; This is enough for most HDDs.&#160; For SSDs or FLASH (USB sticks) or<br />SMR or hybrid drives, you may want to overwrite the whole drive several<br />times to be sure data is not retained.&#160; This is possibly still insecure<br />as the respective technologies are not fully understood in this regard.<br />Still, due to the anti-forensic properties of the LUKS key-slots, a<br />single overwrite could be enough.&#160; If in doubt, use physical destruction<br />in addition.&#160; Here is a link to some current research results on erasing<br />SSDs and FLASH drives: <a href="https://www.usenix.org/events/fast11/tech/full_papers/Wei.pdf" rel="nofollow">https://www.usenix.org/events/fast11/te … rs/Wei.pdf</a></p></div></blockquote></div>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Sat, 16 Jan 2021 11:24:38 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26816#p26816</guid>
		</item>
		<item>
			<title><![CDATA[Re: openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26814#p26814</link>
			<description><![CDATA[<div class="quotebox"><cite>dice wrote:</cite><blockquote><div><p>i still need to figure out how to treat file extensions in and out hence trying to use <span class="bbc">${@%.*}&quot;</span> which will probably work in my shell as i think sh is linked to bash in devuan?</p></div></blockquote></div><p>No, /bin/sh is linked to dash in Devuan. If you want to use bashisms then don&#039;t use a /bin/sh shebang. Fortunately though the <span class="bbc">${parameter%word}</span> expansion is POSIX compliant — see section 2.6.2 of the <a href="https://pubs.opengroup.org/onlinepubs/007904875/utilities/xcu_chap02.html" rel="nofollow">official specification</a>.</p><div class="quotebox"><cite>dice wrote:</cite><blockquote><div><p>This uses secure-delete</p></div></blockquote></div><p>Note that secure-delete is not guaranteed to completely delete files stored on a solid state device thanks to wear-levelling and&#160; over-provisioning. TRIM can help with the former (eventually) but not the latter.</p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Sat, 16 Jan 2021 11:04:32 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26814#p26814</guid>
		</item>
		<item>
			<title><![CDATA[Re: openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26807#p26807</link>
			<description><![CDATA[<p>so here is the final script i have been working on. Usage inside the script.</p><p>This uses secure-delete so might be a bit slow for large files, could always replace it with rm -rf though.</p><div class="codebox"><pre class="vscroll"><code>#!/bin/sh

encrypt_file () {
	openssl enc -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$2&quot; -out &quot;$2&quot;.aes -pass file:&quot;$3&quot;
	srm -v &quot;$2&quot;
}

decrypt_file () {
	openssl enc -d -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$2&quot; -out &quot;${2%.*}&quot; -pass file:&quot;$3&quot;

}

encrypt_dirs () {
	tar -cvzf &quot;$2&quot;.tar.gz &quot;$2&quot; | openssl enc -aes256 -salt -pbkdf2 -iter 20000 -in &quot;$2&quot;.tar.gz -out &quot;$2&quot;.tar.gz.aes -pass file:&quot;$3&quot;
	srm -v &quot;$2&quot;.tar.gz
}

decrypt_dirs () {
	openssl enc -d -aes256 -salt -pbkdf2 -iter 20000 -in &quot;$2&quot; -out &quot;${2%.*}&quot; -pass file:&quot;$3&quot;
	tar xvf &quot;${2%.*}&quot;
	srm -rv &quot;${2%.*}&quot;
}

usage () {
    cat &lt;&lt;EOM

Usage:
[-e]
enc.sh -e file passfile
encrypts file with chosen passfile and removes with secure delete the file leaving only the encrypted file.aes

[-d]
enc.sh -d file passfile
decrypts file.aes with chosen passfile

[-E]
enc.sh -E directory passfile
encrypts a directory to directory.tar.gz.aes with a chosen passfile and removes with secure delete the unencrypted directory.tar.gz leaving the directory.tar.gz.aes

[-D]
enc.sh -D directory passfile
decrypts directory to directory.tar.gz with chosen passfile and extracts directory.tar.gz in place then removes with secure delete the unencrypted directory.tar.gz leaving the encrypted directory.tar.gz.aes 

EOM
    exit 0
}

while getopts &quot;:edEDh&quot; opt; do
  case ${opt} in
	e ) encrypt_file &quot;$@&quot;
	;;
	d ) decrypt_file &quot;$@&quot;
	;;
	E ) encrypt_dirs &quot;$@&quot;
	;;
	D ) decrypt_dirs &quot;$@&quot;
	;;
	h ) usage
       ;;
       *)
       ;;
  esac
done</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Sat, 16 Jan 2021 07:44:39 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26807#p26807</guid>
		</item>
		<item>
			<title><![CDATA[Re: openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26804#p26804</link>
			<description><![CDATA[<p>i dont want to put in bashrc as these commands will be part of a larger script that also encrypts directories.</p><p>I was confused on the positional parameters for what i wanted to achieve.</p><p>Below is close to what i want but i still need to figure out how to treat file extensions in and out hence trying to use <span class="bbc">${@%.*}&quot;</span> which will probably work in my shell as i think sh is linked to bash in devuan?</p><div class="codebox"><pre><code>#!/bin/sh

encrypt_file () {
	openssl enc -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$2&quot; -out &quot;$2&quot;.aes -k &quot;$3&quot;
}

decrypt_file () {
	openssl enc -d -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$2&quot; -out &quot;${2%.*}&quot; -k &quot;$3&quot;
}

while getopts &quot;:ed&quot; opt; do
  case ${opt} in
	e ) encrypt_file &quot;$@&quot;
	;;
	d ) decrypt_file &quot;$@&quot;
	;;
    *)
      ;;
  esac
done</code></pre></div><p>edit: i think i figured out the file extension problem i was having.</p><p>decrypt will accept as the <span class="bbc">-in</span> argument with any file type extension eg; .txt .mp3 etc.., the <span class="bbc">-out</span> argument with <span class="bbc">-out &quot;${2%.*}&quot;</span> will bring back the file to its original thus deleting the<span class="bbc"> .aes</span> extension given to it when it was encrypted.</p><p>@ Head on a stick, my thinking initially for 2 separate scripts was to establish how to get each one to function independantly of one another and then bring them both into one script?</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Fri, 15 Jan 2021 23:44:34 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26804#p26804</guid>
		</item>
		<item>
			<title><![CDATA[Re: openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26803#p26803</link>
			<description><![CDATA[<div class="quotebox"><cite>dice wrote:</cite><blockquote><div><p>This works</p></div></blockquote></div><p>Not for me:</p><div class="codebox"><pre><code>~$ ./dec foo keyfile                                   
./dec[7]: ${@%.*}&quot;: bad substitution
1~$</code></pre></div><p>I am confused as to why you use <span class="bbc">$3</span> and <span class="bbc">$4</span> when there are only two parameters to be applied and also why you call <span class="bbc">$@</span> (which lists all of the positional parameters separated with spaces) three times <img src="https://dev1galaxy.org/img/smilies/hmm.png" width="15" height="15" alt="hmm" /></p><p>These lines in my shell configuration file[0] work for me:</p><div class="codebox"><pre><code>enc () {
   openssl enc -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$1&quot; -out &quot;$1&quot;.aes -k &quot;$2&quot;
}

dec () {
   openssl enc -d -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$1&quot;.aes -out &quot;$1&quot; -k &quot;$2&quot;
}</code></pre></div><p>Then call them with</p><div class="codebox"><pre><code>enc foo keyfile
dec foo keyfile</code></pre></div><p>No need for separate scripts.</p><p>[0] If you use bash as your default interactive shell then put the lines in <span class="bbc">~/.bashrc</span>.</p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Fri, 15 Jan 2021 19:03:44 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26803#p26803</guid>
		</item>
		<item>
			<title><![CDATA[Re: openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26800#p26800</link>
			<description><![CDATA[<div class="quotebox"><cite>bgstack15 wrote:</cite><blockquote><div><p>If I recall correctly, openssl has a relatively small upper limit of file size it can encrypt. I think it was like 1MB in my very unscientific testing.<br />The main way people encrypt files in a Linux and filesystem context is with GPG: <a href="https://www.howtogeek.com/427982/how-to-encrypt-and-decrypt-files-with-gpg-on-linux/" rel="nofollow">https://www.howtogeek.com/427982/how-to … -on-linux/</a></p></div></blockquote></div><p>Thanks but i just encrypted a 70mb file with openssl no problem?</p><p>Im familiar with gpg. What i am trying to accomplish with openssl is to be able to use random keyfiles for different files and directories just for experimentation.</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Fri, 15 Jan 2021 15:15:52 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26800#p26800</guid>
		</item>
		<item>
			<title><![CDATA[Re: openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26799#p26799</link>
			<description><![CDATA[<p>If I recall correctly, openssl has a relatively small upper limit of file size it can encrypt. I think it was like 1MB in my very unscientific testing.<br />The main way people encrypt files in a Linux and filesystem context is with GPG: <a href="https://www.howtogeek.com/427982/how-to-encrypt-and-decrypt-files-with-gpg-on-linux/" rel="nofollow">https://www.howtogeek.com/427982/how-to … -on-linux/</a></p>]]></description>
			<author><![CDATA[dummy@example.com (bgstack15)]]></author>
			<pubDate>Fri, 15 Jan 2021 14:52:20 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26799#p26799</guid>
		</item>
		<item>
			<title><![CDATA[openssl file encryption scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26798#p26798</link>
			<description><![CDATA[<p>this will probably show my bad lack of understanding but here goes. I have two scripts, one for encryption and another for decryption.</p><p>scenario is to say i have file foo on disk i want to encrypt with a keyfile using openssl all i want to type is the following in code snippet thus reducing keystrokes.</p><p><span class="bbc">enc.sh foo keyfile</span></p><p>likewise i want to decrypt the same way</p><p><span class="bbc">dec.sh foo keyfile</span></p><p>the encryption script:</p><div class="codebox"><pre><code>#!/bin/sh
set -x
encrypt_file () {
	openssl enc -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$1&quot; -out &quot;$3&quot;.aes -k &quot;$4&quot;
}

encrypt_file &quot;$@&quot; &quot;$@&quot; &quot;$@&quot;</code></pre></div><p>the decryption script</p><div class="codebox"><pre><code>#!/bin/sh
set -x
decrypt_file () {
	openssl enc -d -aes-256-cbc -salt -pbkdf2 -iter 20000 -in &quot;$1&quot;.aes -out &quot;$3&quot; -k &quot;$4&quot;
}

decrypt_file &quot;$@&quot; &quot;${@%.*}&quot; &quot;$@&quot;</code></pre></div><p>This works but im wondering if this is the right way ?</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Fri, 15 Jan 2021 14:33:38 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26798#p26798</guid>
		</item>
	</channel>
</rss>
