jhaals / yopass

Secure sharing of secrets, passwords and files
https://yopass.se
Apache License 2.0
1.87k stars 290 forks source link

API: How to encrypt a file with command line and send it to yopass server? #2506

Open arbdevml opened 1 month ago

arbdevml commented 1 month ago

Hello, first of all very big thank you for this project. Example of the command line script encrypting text message:

#!/bin/bash

message=$1;
password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 20 );

GNUPGHOME=$(mktemp -d /tmp/.gnupgXXXXXX);
export GNUPGHOME;

# encrypt message with $password and replace newlines with "\n";
message=$(echo $message | gpg -a --batch --passphrase $password -c  --cipher-algo AES256 | sed ':a;N;$!ba;s/\n/\\n/g');

payload=$(cat << EOF
{
  "message": "${message}",
  "expiration": 604800 ,
  "one_time": true
}
EOF
);

secret_id=$(curl -k -s -XPOST https://yopass.se/secret -H 'Content-Type: application/json' -d "${payload}" |  jq -r .message);
echo "https://yopass.se/#/s/$secret_id/$password";

The command line encrypt: echo "text" | gpg -a --batch --passphrase "password" -c --cipher-algo AES256 >./text.gpg && cat ./text.gpg

The command line decrypt: gpg -d --pinentry-mode loopback --passphrase "password" --batch ./text.gpg 2>/dev/null

What command line alternative of this encrypt function:

encrypt({
          format: 'armored',
          message: await createMessage({
            binary: new Uint8Array(reader.result as ArrayBuffer),
            filename: acceptedFiles[0].name,
          }),
          passwords: pw,
});

How to encrypt a file with command line and send it to yopass server? Thank you for your answer.