An open API service indexing awesome lists of open source software.

https://github.com/g-crypt/g-crypt

Simple encryption library in Go using AES-256.
https://github.com/g-crypt/g-crypt

aes-encryption aes256 crypter-2024 crypto decryption encryption golang library

Last synced: 6 months ago
JSON representation

Simple encryption library in Go using AES-256.

Awesome Lists containing this project

README

          

# G-Crypt

Simple encryption library in Go using AES-256.

[![codecov](https://codecov.io/github/g-crypt/g-crypt/branch/master/graph/badge.svg?token=DZT5RJ1S8U)](https://codecov.io/github/g-crypt/g-crypt)

## Installation

To install the package, run the following command:

```bash
go get github.com/g-crypt/g-crypt
```

Or

```bash
go install github.com/g-crypt/g-crypt
```

### Usage

Here is an example of how to use the encryption and decryption functions provided by the g-crypt package:

```go
package main

import (
"fmt"
gcrypt "github.com/g-crypt/g-crypt"
)

func main() {
text := "Hello World"
password := "secret-password"

// Encrypt the text
encrypted, err := gcrypt.EncryptAES256(text, password)
if err != nil {
fmt.Println("Error encrypting:", err)
return
}
fmt.Println("Encrypted text:", encrypted)

// Decrypt the text
decrypted, err := gcrypt.DecryptAES256(encrypted, password)
if err != nil {
fmt.Println("Error decrypting:", err)
return
}
fmt.Println("Decrypted text:", string(decrypted))
}
```

### Functions
#### EncryptAES256
```go
func EncryptAES256(text, password string) (string, error)
```
Encrypts a text using AES-256.

- `text`: The text to be encrypted.
- `password`: The password used to generate the encryption key.

Returns the encrypted text in base64 or an error if it occurs.

#### DecryptAES256
```go
func DecryptAES256(encryptedText, password string) ([]byte, error)
```
Decrypts a text encrypted using AES-256.

- `encryptedText`: The encrypted text in base64.
- `password`: The password used to generate the encryption key.

Returns the decrypted text as a byte slice or an error if it occurs.