添加加密字符串脚本以支持文本加密功能
This commit is contained in:
33
scripts/encrypt_string.py
Normal file
33
scripts/encrypt_string.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# 将项目根目录添加到 python 路径
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||||
|
|
||||||
|
from app.core.encryption import get_database_encryptor
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
plaintext = None
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
stdin_text = sys.stdin.read()
|
||||||
|
if stdin_text != "":
|
||||||
|
plaintext = stdin_text.rstrip("\r\n")
|
||||||
|
if plaintext is None and len(sys.argv) >= 2:
|
||||||
|
plaintext = sys.argv[1]
|
||||||
|
if plaintext is None:
|
||||||
|
try:
|
||||||
|
plaintext = input("请输入要加密的文本: ")
|
||||||
|
except EOFError:
|
||||||
|
plaintext = ""
|
||||||
|
if not plaintext.strip():
|
||||||
|
print("Error: plaintext string cannot be empty.", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
token = get_database_encryptor().encrypt(plaintext)
|
||||||
|
print(token)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
Reference in New Issue
Block a user