mirror of
https://github.com/5im-0n/sshenc.sh.git
synced 2025-08-03 11:50:04 +02:00
Compare commits
3 Commits
c83123b09a
...
7524cf078a
Author | SHA1 | Date | |
---|---|---|---|
7524cf078a | |||
6cc79ed5b4 | |||
928d45a383 |
@@ -1,5 +1,5 @@
|
|||||||
# sshenc.sh
|
# sshenc.sh
|
||||||
> bash script to encrypt data using a users ssh public key.
|
**bash script to encrypt data using a users ssh public key**
|
||||||
|
|
||||||
If you received a message from someone that was encrypted with this script, you can decrypt it with your ssh private key using the following command without installing anything:
|
If you received a message from someone that was encrypted with this script, you can decrypt it with your ssh private key using the following command without installing anything:
|
||||||
```
|
```
|
||||||
|
17
sshenc.sh
17
sshenc.sh
@@ -41,8 +41,8 @@ shift $((OPTIND -1))
|
|||||||
[ "$1" = "--" ] && shift
|
[ "$1" = "--" ] && shift
|
||||||
|
|
||||||
temp_dir="$(mktemp -d -t "$me.XXXXXX")"
|
temp_dir="$(mktemp -d -t "$me.XXXXXX")"
|
||||||
temp_file_key="$(mktemp "$temp_dir/$(basename "$0").XXXXXX.key")"
|
temp_file_key="$(mktemp "$temp_dir/$me.XXXXXX.key")"
|
||||||
temp_file="$(mktemp "$temp_dir/$(basename "$0").XXXXXX.cypher")"
|
temp_file="$(mktemp "$temp_dir/$me.XXXXXX.cypher")"
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
#encrypt
|
#encrypt
|
||||||
@@ -54,13 +54,14 @@ if [[ "${#public_key[@]}" > 0 ]]; then
|
|||||||
for pubkey in "${public_key[@]}"
|
for pubkey in "${public_key[@]}"
|
||||||
do
|
do
|
||||||
if [[ -e "$pubkey" ]]; then
|
if [[ -e "$pubkey" ]]; then
|
||||||
echo "-- key"
|
|
||||||
convertedpubkey=$temp_dir/$(basename "$pubkey").pem
|
convertedpubkey=$temp_dir/$(basename "$pubkey").pem
|
||||||
ssh-keygen -f "$pubkey" -e -m PKCS8 > $convertedpubkey
|
ssh-keygen -f "$pubkey" -e -m PKCS8 > $convertedpubkey
|
||||||
#encrypt key with public keys
|
#encrypt key with public keys
|
||||||
openssl rsautl -encrypt -pubin -inkey "$convertedpubkey" -in "$temp_file_key" -out $temp_dir/$(basename "$pubkey").key.enc
|
if openssl rsautl -encrypt -pubin -inkey "$convertedpubkey" -in "$temp_file_key" -out $temp_dir/$(basename "$pubkey").key.enc; then
|
||||||
openssl base64 -in $temp_dir/$(basename "$pubkey").key.enc
|
echo "-- key"
|
||||||
echo "-- /key"
|
openssl base64 -in $temp_dir/$(basename "$pubkey").key.enc
|
||||||
|
echo "-- /key"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "-- /keys"
|
echo "-- /keys"
|
||||||
@@ -92,8 +93,8 @@ elif [[ -e "$private_key" ]]; then
|
|||||||
if ((echo "$key" | openssl base64 -d | openssl rsautl -decrypt -ssl -inkey "$private_key" > "$temp_file") > /dev/null 2>&1); then
|
if ((echo "$key" | openssl base64 -d | openssl rsautl -decrypt -ssl -inkey "$private_key" > "$temp_file") > /dev/null 2>&1); then
|
||||||
if echo "$cypher" | openssl base64 -d | openssl aes-256-cbc -d -pass file:"$temp_file"; then
|
if echo "$cypher" | openssl base64 -d | openssl aes-256-cbc -d -pass file:"$temp_file"; then
|
||||||
decrypted=true
|
decrypted=true
|
||||||
fi;
|
fi
|
||||||
fi;
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $decrypted = false ]; then
|
if [ $decrypted = false ]; then
|
||||||
|
Reference in New Issue
Block a user