cryptos

package module
v0.0.0-...-a64609e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 9 Imported by: 0

README

Go Cryptos

Cryptos is a Go library that implements a simple string encrypt/decrypt.

Getting Started

Just a quick example how to use the cryptos library:

main.go
package main

import (
	"flag"
	"fmt"

	"encoding/base64"
	"github.com/jattschneider/cryptos"
)

func init() {
	flag.Parse()
}

func main() {
	
	// 32 bytes Key
	key, err := base64.StdEncoding.DecodeString("lJVRh3lGtxZwlwplx+Wz9XbJSEouhfcPKmYbBM45ODE=")
	if err != nil {
		return
	}
	// 12 bytes Nonce
	nonce, err := base64.StdEncoding.DecodeString("hoOLlooQPN21ufCy")
	if err != nil {
		return
	}

	
	msg := "Hello Encrypter!"
	es, err := cryptos.EncryptString(key, nonce, msg)
	if err != nil {
		return
	}
	
	// AES-256
	// "ENC(cLqUafMcfzJOt3FyOLmIAqwVJJAoXj3o3h3cZrM4EIo=)"
	if !cryptos.IsEncryptedString(es) {
		return
	}

	ds, err := cryptos.DecryptString(key, nonce, es)
	if err != nil {
		return
	}

}
$ go run main.go
Installing
go get -v github.com/jattschneider/cryptos

Built With

  • Go - The Go Programming Language

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64DecodeInnerEncryptedString

func Base64DecodeInnerEncryptedString(s string) ([]byte, error)

Base64DecodeInnerEncryptedString returns the bytes represented by the base64 inner "encrypted string" surrounded by ENC(...).

func Base64EncodeEncryptedString

func Base64EncodeEncryptedString(src []byte) string

Base64EncodeEncryptedString returns the base64 encoding of "encrypted string" surrounded by ENC(...).

func DecryptString

func DecryptString(key, nonce []byte, s string) (string, error)

DecryptString decrypts a string s

func EncryptString

func EncryptString(key, nonce []byte, s string) (string, error)

EncryptString encrypts a string s.

func GCMDecrypt

func GCMDecrypt(key, nonce, ciphertext []byte) ([]byte, error)

GCMDecrypt the key argument should be the AES key, either 16 or 32 bytes to select AES-128 or AES-256.

func GCMEncrypt

func GCMEncrypt(key, nonce, plaintext []byte) ([]byte, error)

GCMEncrypt the key argument should be the AES key, either 16 or 32 bytes to select AES-128 or AES-256.

func InnerEncryptedString

func InnerEncryptedString(s string) string

InnerEncryptedString returns the inner "encrypted string" surrounded by ENC(...).

func IsEncryptedString

func IsEncryptedString(s string) bool

IsEncryptedString a string is considered "encrypted" when it appears surrounded by ENC(...).

func Key16

func Key16(password []byte) ([]byte, error)

Key16 generates AES-128 16 bytes key

func Key32

func Key32(password []byte) ([]byte, error)

Key32 generates AES-256 32 bytes key

func Nonce

func Nonce() ([]byte, error)

Nonce never use more than 2^32 random nonces with a given key because of the risk of a repeat.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL