34 lines
897 B
Python
34 lines
897 B
Python
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())
|