Skip to content

Instantly share code, notes, and snippets.

@nabsha
Created May 6, 2022 00:51
Show Gist options
  • Save nabsha/0d3c8c14f7caecf053c5e0b0dddc9649 to your computer and use it in GitHub Desktop.
Save nabsha/0d3c8c14f7caecf053c5e0b0dddc9649 to your computer and use it in GitHub Desktop.
A quick hack to re encrypting mule secure properties file
#!/bin/bash
if [ "$#" -ne 4 ]; then
echo "usage: ./reencrypt.sh <Algo> <Key Source> <source file> <Key Target>";
exit -1;
fi
ALGO=$1
KEY_SOURCE=$2
FILE=$3
KEY_TARGET=$4
if [ ! -f "$FILE" ]; then
echo "$FILE does not exists."
exit -1;
fi
while IFS='=' read -r k v; do
if [[ $k = *[!\ ]* ]] && [[ $v = *[!\ ]* ]]; then
if [[ $v =~ \!\[(.*)$ ]]; then
ENCRYPTED=${BASH_REMATCH[1]}
ENC=${ENCRYPTED::-2}
DECRYPTED_STRING=$(docker run --rm nabsha/docker-mule-secure-tool decrypt $ALGO $KEY_SOURCE $ENC)
ENCRYPTED_STRING=$(docker run --rm nabsha/docker-mule-secure-tool encrypt $ALGO $KEY_TARGET $DECRYPTED_STRING)
echo "$k=![$ENCRYPTED_STRING]"
fi
fi
done < "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment