Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bitlytwiser/tinycrypt
Tiny library for encrypting files and byte streams
https://github.com/bitlytwiser/tinycrypt
encryption encryption-decryption files go golang
Last synced: 6 days ago
JSON representation
Tiny library for encrypting files and byte streams
- Host: GitHub
- URL: https://github.com/bitlytwiser/tinycrypt
- Owner: BitlyTwiser
- License: mit
- Created: 2022-09-10T17:03:29.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-25T17:33:07.000Z (almost 2 years ago)
- Last Synced: 2024-08-16T11:38:24.359Z (3 months ago)
- Topics: encryption, encryption-decryption, files, go, golang
- Language: Go
- Homepage:
- Size: 1.09 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tinycrypt
[![Go Report Card](https://goreportcard.com/badge/github.com/BitlyTwiser/tinycrypt)](https://goreportcard.com/report/github.com/BitlyTwiser/tinycrypt)
Tiny library for encrypting files and byte streams.
# Installation:
```go get github.com/BitlyTwiser/tinychunk```# Testing:
- Initially run ```go mod tidy``` to install necessary packages.
- One can test the module via utilizing the go test framework.
```go test tinycrypt_test.go -v```# Usage:
- Example usage can be seen within the test file.```
package tinycrypt_testimport (
. "github.com/BitlyTwiser/tinycrypt"
"testing""github.com/stretchr/testify/assert"
)func TestOpenFile(t *testing.T) {
t.Skip("Do not run else it will erase the file for testing due to the append nature of opening the file. This is present for either a generic test run or viewing functionality")
badVal, fileData, _ := OpenFile("../IDoNotExist.txt")//We expect nil here as the file does not exist.
assert.Nil(t, badVal)
assert.Nil(t, fileData)existingVal, fileData, _ := OpenFile("./testing/testing_files/items.txt")
if assert.NotNil(t, *existingVal) && assert.NotNil(t, *fileData) {
t.Log("File exists properly")
}
}func TestFileEncrypt(t *testing.T) {
enc := Encryption{FilePath: "./testing/testing_files/test.txt", SecureString: "Password123adar$"}err := enc.Encrypt()
assert.Nil(t, err)
}func TestFileDecrypt(t *testing.T) {
enc := Encryption{FilePath: "./testing/testing_files/test.txt", SecureString: "Password123adar$"}err := enc.Decrypt()
//Ensure that decryption does not fail.
assert.Nil(t, err)
}func TestPdfEncrypt(t *testing.T) {
enc := Encryption{FilePath: "./testing/testing_files/test.pdf", SecureString: "Password123adar$"}err := enc.Encrypt()
assert.Nil(t, err)
}func TestPdfDecrypt(t *testing.T) {
enc := Encryption{FilePath: "./testing/testing_files/test.pdf", SecureString: "Password123adar$"}err := enc.Decrypt()
//Ensure that decryption does not fail.
assert.Nil(t, err)
}func TestBadFileType(t *testing.T) {
enc := Encryption{FilePath: "./testing/testing_files/test", SecureString: "Password123adar$"}err := enc.Encrypt()
assert.NotNil(t, err)
}func TestEncryptAndDecryptOfFileStream(t *testing.T) {
testingPass := "Password123adar$"
t.Log("Testing Encryption of stream")
words := []byte("Blue Red Green")stream, err := EncryptByteStream(testingPass, words)
assert.NotNil(t, stream)
assert.Nil(t, err)t.Logf("Encrypted Stream: %v", stream)
t.Log("Testing Decryption of stream")
decryptedStream, err := DecryptByteStream(testingPass, *stream)
assert.Nil(t, err)
assert.NotNil(t, decryptedStream)t.Logf("Decrypted String: %v", string(*decryptedStream))
}
```