29 lines
878 B
Bash
29 lines
878 B
Bash
#!/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
|