Created
July 1, 2025 13:49
-
-
Save yosugi/10912a9501de57ab7f66e1ec43b8b35f to your computer and use it in GitHub Desktop.
ppc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ppc: Password PGP CLI - Simple password-based encryption/decryption tool | |
| # Usage: | |
| # export PPC_PASSWORD='secret' && cat .env | ppc -e > enc.env | |
| # export PPC_PASSWORD='secret' && cat enc.env | ppc -d > .env | |
| # | |
| # LICENSE: MIT | |
| # IntentScript specification for this tool: | |
| : << 'INTENTSCRIPT' | |
| # ppc: パスワード暗号化でファイル暗号化/復号するCLIツール | |
| # https://claude.ai/chat/52ff8c2e-38c5-4849-af4a-3135089cc673 | |
| Ppc: | |
| name: "ppc (Password Pgp Cli)" | |
| usage: | |
| encrypt: "export PPC_PASSWORD='secret' && cat .env | ppc --encrypt > enc.env" | |
| decrypt: "export PPC_PASSWORD='secret' && cat enc.env | ppc --decrypt > .env" | |
| short: "ppc -e または ppc -d でも可" | |
| arguments: | |
| - "-e --encrypt 暗号化する" | |
| - "-d --decrypt 復号する" | |
| input: stdin "暗号化/復号対象のテキスト" | |
| output: stdout "処理結果のテキスト" | |
| implementation: | | |
| gpg --symmetricコマンドのシンプルなラッパー。 | |
| 環境変数PPC_PASSWORDからパスワードを取得 | |
| 暗号化: gpg --symmetric --cipher-algo AES256 --armor --batch --passphrase-fd 0 | |
| 復号: gpg --decrypt --batch --passphrase-fd 0 | |
| dependencies: | |
| - gpg | |
| INTENTSCRIPT | |
| set -e | |
| show_help() { | |
| cat << 'EOF' | |
| ppc (Password PGP CLI) - Simple password-based encryption/decryption tool | |
| Usage: | |
| export PPC_PASSWORD='secret' && cat file | ppc -e > encrypted.txt | |
| export PPC_PASSWORD='secret' && cat encrypted.txt | ppc -d > file | |
| Options: | |
| -e, --encrypt Encrypt from stdin using PPC_PASSWORD | |
| -d, --decrypt Decrypt from stdin using PPC_PASSWORD | |
| -h, --help Show this help | |
| Environment: | |
| PPC_PASSWORD Password for encryption/decryption (required) | |
| Examples: | |
| # Set password and encrypt .env file | |
| export PPC_PASSWORD='my-super-secret-password' | |
| cat .env | ppc -e > secrets.env.asc | |
| # Decrypt back to original | |
| cat secrets.env.asc | ppc -d > .env | |
| # One-liner (password in command) | |
| PPC_PASSWORD='secret' cat .env | ppc -e > enc.env | |
| Security Notes: | |
| - Use a strong password for PPC_PASSWORD | |
| - Consider storing password in a password manager | |
| - Never commit PPC_PASSWORD to version control | |
| EOF | |
| } | |
| check_dependencies() { | |
| if ! command -v gpg >/dev/null 2>&1; then | |
| echo "Error: gpg command not found. Please install GnuPG." >&2 | |
| exit 1 | |
| fi | |
| } | |
| check_password() { | |
| if [ -z "$PPC_PASSWORD" ]; then | |
| echo "Error: PPC_PASSWORD environment variable is not set." >&2 | |
| echo "Usage: export PPC_PASSWORD='your-password' && ppc -e/-d" >&2 | |
| exit 1 | |
| fi | |
| } | |
| encrypt_data() { | |
| check_password | |
| gpg --symmetric --cipher-algo AES256 --armor --batch --yes --quiet --passphrase "$PPC_PASSWORD" --pinentry-mode loopback | |
| } | |
| decrypt_data() { | |
| check_password | |
| gpg --decrypt --batch --yes --quiet --passphrase "$PPC_PASSWORD" --pinentry-mode loopback | |
| } | |
| # メイン処理 | |
| case "${1:-}" in | |
| -e|--encrypt) | |
| check_dependencies | |
| encrypt_data | |
| ;; | |
| -d|--decrypt) | |
| check_dependencies | |
| decrypt_data | |
| ;; | |
| -h|--help|"") | |
| show_help | |
| ;; | |
| *) | |
| echo "Error: Unknown option '$1'" >&2 | |
| echo "Use 'ppc --help' for usage information." >&2 | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment