Create

key="sososecret"
loop=$(losetup -f)
container=secrets
secret_path=/mnt/secrets.enc
dd if=/dev/urandom of=${secret_path} bs=1M count=1024 # size in MB
losetup $loop ${secret_path}
echo -n $key | cryptsetup -c aes-xts-plain -s 512 luksFormat $loop -
echo -n $key | cryptsetup luksOpen $loop $container -
mkfs.ext4 /dev/mapper/$container

Mount

key="sososecret"
secret_path=/mnt/secrets.enc
mnt_path=/mnt/secrets
loop=$(losetup -f)
container=secrets

losetup $loop ${secret_path}
echo -n ${key} | cryptsetup luksOpen $loop $container -
mount /dev/mapper/${container} ${mnt_path}