scripts/alert/bark/ciphertxt.sh

29 lines
878 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Documentation: https://bark.day.app/#/encryption
set -e
# bark key
deviceKey='R5BU8VnMn3ufSFjMnwSmd6'
# push payload
# json='{"body": "test", "sound": "birdsong"}'
json=`cat /opt/scripts/alert/bark/option.json`
# 必须32位
key='sqCT9wE25eS2kMYu6BCGN4f9ymx2Fsmj'
# IV可以是随机生成的但如果是随机的就需要放在 iv 参数里传递。
iv='QA475QXtg4YaGQzc'
# OpenSSL 要求输入的 Key 和 IV 需使用十六进制编码。
key=$(printf $key | xxd -ps -c 200)
iv=$(printf $iv | xxd -ps -c 200)
ciphertext=$(echo -n $json | openssl enc -aes-256-cbc -K $key -iv $iv | base64)
# 删除密文中的空格
ciphertext=`echo $ciphertext | tr -d ' '`
# 密文可能有特殊字符,所以记得 URL 编码一下。
curl --data-urlencode "ciphertext=$ciphertext" --data-urlencode "iv=QA475QXtg4YaGQzc" https://bark.rustle.cc/$deviceKey