https://github.com/watchakorn-18k/easycrypt
🔐 EasyCrypt is a Go package that provides straightforward encryption and decryption functionality using AES encryption with a passphrase.
https://github.com/watchakorn-18k/easycrypt
encryption-decryption go go-module golang
Last synced: over 1 year ago
JSON representation
🔐 EasyCrypt is a Go package that provides straightforward encryption and decryption functionality using AES encryption with a passphrase.
- Host: GitHub
- URL: https://github.com/watchakorn-18k/easycrypt
- Owner: watchakorn-18k
- License: unlicense
- Created: 2024-07-10T12:01:13.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-10T13:58:38.000Z (almost 2 years ago)
- Last Synced: 2025-01-11T01:30:02.821Z (over 1 year ago)
- Topics: encryption-decryption, go, go-module, golang
- Language: Go
- Homepage: https://pkg.go.dev/github.com/watchakorn-18k/easycrypt
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: .github/readme.md
- License: LICENSE
Awesome Lists containing this project
README
# EasyCrypt
🔐 EasyCrypt is a Go package that provides straightforward encryption and decryption functionality using AES encryption with a passphrase.
## Project Origin
🤖 This project originated from ChatGPT, but I injected some creative ideas to bring this code to life. So, while I won't claim to be the creator, let's just have fun with it! 😎
## Installation
To use EasyCrypt, ensure you have Go installed and configured. Use the following command to install the package:
```sh
go get github.com/watchakorn-18k/easycrypt
```
## Usage
Import EasyCrypt in your Go code:
```go
import (
"fmt"
"log"
"github.com/watchakorn-18k/easycrypt"
)
```
### Functions
#### generateKey
```go
func generateKey(passphrase string) []byte
```
Generates a 32-byte key from a passphrase using SHA-256.
#### Encrypt
```go
func Encrypt(passphrase, plaintext string) (string, error)
```
Encrypts the provided plaintext using AES encryption with the given passphrase. Returns the base64 URL encoded ciphertext and any encountered error.
#### Decrypt
```go
func Decrypt(passphrase, cryptoText string) (string, error)
```
Decrypts the base64 encoded ciphertext using AES encryption with the provided passphrase. Returns the plaintext and any encountered error.
### Example
```go
package main
import "github.com/watchakorn-18k/easycrypt"
func main() {
secretKey := "password"
text := "wk18k"
// Encrypt the plaintext
encrypted, err := easycrypt.Encrypt(secretKey, text)
if err != nil {
panic(err)
}
println("encrypted: ", encrypted)
// Decrypt the encrypted text
decrypted, err := easycrypt.Decrypt(secretKey, encrypted)
if err != nil {
panic(err)
}
println("decrypted: ", decrypted)
}
```
## License
This project is licensed under the Unlicense license