Update README.md

Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
This commit is contained in:
Jan Tytgat
2025-01-13 17:23:15 +01:00
parent 655d3fb7e6
commit aa785c77a0

View File

@ -21,3 +21,62 @@ Next, you can manually add the import statement to your ```.go```-file, or have
```text ```text
import github.com/jantytgat/go-transcrypt 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.