-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "paseto.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
// Loads v2.local-encrypted data from stdin, decrypts it using the hex-encoded | ||
// key in the PASETO_V2_LOCAL_SECRET environment variable and writes decrypted | ||
// data to stdout. The footer is not written to stdout. | ||
|
||
|
||
static const size_t BUF_SIZE = 64*1024; | ||
|
||
|
||
int main() { | ||
if (!paseto_init()) { | ||
fprintf(stderr, "Failed to initialize libpaseto\n"); | ||
exit(-1); | ||
} | ||
|
||
uint8_t key[paseto_v2_LOCAL_KEYBYTES]; | ||
if (!paseto_v2_local_load_key_base64(key, | ||
getenv("PASETO_V2_LOCAL_SECRET"))) { | ||
perror("Failed to load key"); | ||
exit(-1); | ||
} | ||
char *encrypted = malloc(BUF_SIZE); | ||
if (!encrypted) { | ||
perror("Failed to allocate input buffer"); | ||
exit(-1); | ||
} | ||
size_t encrypted_len = fread(encrypted, 1, BUF_SIZE - 1, stdin); | ||
encrypted[encrypted_len] = '\0'; | ||
size_t message_len; | ||
uint8_t *message = paseto_v2_local_decrypt( | ||
encrypted, &message_len, key, NULL, NULL); | ||
free(encrypted); | ||
if (!message) { | ||
perror("paseto_v2_local_decrypt failed"); | ||
exit(-1); | ||
} | ||
fwrite(message, 1, message_len, stdout); | ||
paseto_free(message); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "paseto.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
// Loads data from stdin, encrypts it using the hex-encoded key in the | ||
// PASETO_V2_LOCAL_SECRET environment variable and writes encrypted data to | ||
// stdout. A footer can not be specified. | ||
|
||
|
||
static const size_t BUF_SIZE = 64*1024; | ||
|
||
|
||
int main() { | ||
if (!paseto_init()) { | ||
fprintf(stderr, "Failed to initialize libpaseto\n"); | ||
exit(-1); | ||
} | ||
|
||
uint8_t key[paseto_v2_LOCAL_KEYBYTES]; | ||
if (!paseto_v2_local_load_key_base64(key, | ||
getenv("PASETO_V2_LOCAL_SECRET"))) { | ||
perror("Failed to load key"); | ||
exit(-1); | ||
} | ||
uint8_t *message = malloc(BUF_SIZE); | ||
if (!message) { | ||
perror("Failed to allocate input buffer"); | ||
exit(-1); | ||
} | ||
size_t message_len = fread(message, 1, BUF_SIZE - 1, stdin); | ||
char *encrypted = paseto_v2_local_encrypt( | ||
message, message_len, key, NULL, 0); | ||
free(message); | ||
if (!encrypted) { | ||
perror("paseto_v2_local_encrypt failed"); | ||
exit(-1); | ||
} | ||
puts(encrypted); | ||
paseto_free(encrypted); | ||
} |
This file contains 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
This file contains 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