7 Commits

Author SHA1 Message Date
0795add410 Merge pull request #2 from jantytgat/dependabot/go_modules/golang.org/x/crypto-0.33.0 2025-02-10 12:13:30 +00:00
c8d89a01ae Bump golang.org/x/crypto from 0.32.0 to 0.33.0
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.32.0 to 0.33.0.
- [Commits](https://github.com/golang/crypto/compare/v0.32.0...v0.33.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-10 05:04:38 +00:00
aa785c77a0 Update README.md
Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
2025-01-13 17:23:15 +01:00
655d3fb7e6 Rename example directory
Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
2025-01-13 17:22:17 +01:00
01efabd841 Remove .gitkeep
Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
2025-01-13 17:22:02 +01:00
68fcee7425 Update README.md
Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
2025-01-13 17:12:57 +01:00
8e6c4cf2a8 Update example key size to 2048 bits
Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
2025-01-13 16:58:08 +01:00
5 changed files with 89 additions and 10 deletions

View File

@ -1 +1,82 @@
# go-transcrypt
This library enables the encryption/decryption of arbitrary data into a hex-encoded string for safe on-disk storage.
[![Go Reference](https://pkg.go.dev/badge/github.com/jantytgat/go-transcrypt.svg)](https://pkg.go.dev/github.com/jantytgat/go-transcrypt)
---
## Basics
### Add the package to your project
```bash
go get github.com/jantytgat/go-transcrypt
```
### Import
Next, you can manually add the import statement to your ```.go```-file, or have it added automatically when using it.
```text
import github.com/jantytgat/go-transcrypt
```
### Encryption key
The encryption key is a string provide to encrypt the data with.
A function ```CreateHexKey(bitSize int)``` is available to create a random key based on an RSA Private Key, and returns
it as a hex-encoded string.
```go
var err error
var key string
if key, err = transcrypt.CreateHexKey(2048); err != nil {
panic(err)
}
```
### Salt
A salt is also required for proper encryption.
It is possible to either generate a new salt for every call, by leaving the salt to ```nil``` when calling the ``
Encrypt``` function.
If you want to use a specific salt, you can either provide it manually (at least 12 bytes) or generate one.
```go
var salt []byte
if salt, err = transcrypt.CreateSalt(); err != nil {
panic(err)
}
```
## Operations
Currently, the following data types are supported for encryption:
- string
- int
### Encrypt
```go
var inputString = "hello world"
var encryptedString string
if encryptedString, err = transcrypt.Encrypt(key, salt, transcrypt.AES_256_GCM, inputString); err != nil {
panic(err)
}
```
### Decrypt
```go
var decryptedString any
if decryptedString, err = transcrypt.Decrypt(key, encryptedString); err != nil {
panic(err)
}
```
## Example
An example is available in the [examples](https://github.com/jantytgat/go-transcrypt/tree/main/examples/simple)
directory.

View File

View File

@ -9,7 +9,7 @@ import (
func main() {
var err error
var key string
if key, err = transcrypt.CreateHexKey(12); err != nil {
if key, err = transcrypt.CreateHexKey(2048); err != nil {
panic(err)
}

4
go.mod
View File

@ -4,7 +4,7 @@ go 1.23
require (
github.com/minio/sio v0.4.1
golang.org/x/crypto v0.32.0
golang.org/x/crypto v0.33.0
)
require golang.org/x/sys v0.29.0 // indirect
require golang.org/x/sys v0.30.0 // indirect

10
go.sum
View File

@ -1,8 +1,6 @@
github.com/minio/sio v0.4.1 h1:EMe3YBC1nf+sRQia65Rutxi+Z554XPV0dt8BIBA+a/0=
github.com/minio/sio v0.4.1/go.mod h1:oBSjJeGbBdRMZZwna07sX9EFzZy+ywu5aofRiV1g79I=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=