Skip to content

Commit

Permalink
aesx: example: add aes jpg file encrypt and decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
wuriyanto48 committed Nov 13, 2022
1 parent d7b010b commit d1fe0fd
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion _examples/aes_file_decrypt/decrypted_file.bin

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions _examples/aes_file_decrypt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ func main() {
// digital signature with RSA
myFile, err := os.Open("decrypted_file.bin")
if err != nil {
fmt.Println("error: open my_file.txt")
fmt.Println("error: open decrypted_file")
os.Exit(1)
}

defer func() { myFile.Close() }()

key, _ := hex.DecodeString("6368616e676520746869732070617373")
key, _ := hex.DecodeString("6368616e6765207468697320706173736368616e676520746869732070617373")
decryptedData, err := io.ReadAll(myFile)
if err != nil {
fmt.Println("error: read all my_file.txt")
fmt.Println("error: read all decrypted_file")
os.Exit(1)
}

plainDataDecrypted, err := aesx.DecryptWithAES128GCM(key, decryptedData)
plainDataDecrypted, err := aesx.DecryptWithAES256GCM(key, decryptedData)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

outputFile, err := os.Create("out.txt")
outputFile, err := os.Create("out.jpg")
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
Binary file added _examples/aes_file_decrypt/out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions _examples/aes_file_decrypt/out.txt

This file was deleted.

Binary file added _examples/aes_file_encrypt/Gopher.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions _examples/aes_file_encrypt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (

func main() {
// digital signature with RSA
myFile, err := os.Open("my_file.txt")
myFile, err := os.Open("Gopher.jpg")
if err != nil {
fmt.Println("error: open my_file.txt")
fmt.Println("error: open Gopher.jpg")
os.Exit(1)
}

defer func() { myFile.Close() }()

key, _ := hex.DecodeString("6368616e676520746869732070617373")
key, _ := hex.DecodeString("6368616e6765207468697320706173736368616e676520746869732070617373")
plainData, err := io.ReadAll(myFile)
if err != nil {
fmt.Println("error: read all my_file.txt")
fmt.Println("error: read all Gopher.jpg")
os.Exit(1)
}

aesData, err := aesx.EncryptWithAES128GCM(key, plainData)
aesData, err := aesx.EncryptWithAES256GCM(key, plainData)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
6 changes: 0 additions & 6 deletions _examples/aes_file_encrypt/my_file.txt

This file was deleted.

2 changes: 1 addition & 1 deletion _examples/aes_file_encrypt/out.bin

Large diffs are not rendered by default.

0 comments on commit d1fe0fd

Please sign in to comment.