uconn

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 15 Imported by: 0

README

Uconn

Uconn (uglify connection) is a lightweight Go library that provides seamless encryption for TCP traffic using pre-shared keys. Built for simplicity and security, it allows network communication encryption with minimal overhead.

Supported encryption algos.

  1. AES 256 GCM (Key size: 32 bytes)
  2. AES 128 GCM (Key size: 16 bytes)

Installation

go get github.com/dipakw/uconn

Example

package main

import (
	"fmt"
	"net"
	"uconn"
)

func main() {
	opts := &uconn.Opts{
		Algo: uconn.ALGO_AES256_GCM,
		Key:  []byte("nbhdhfshdfjgsjhdfgsftqdtdfdfkoko"),
	}

	client, server := net.Pipe()

	cc, _ := uconn.New(client, opts)
	ss, _ := uconn.New(server, opts)

	go func() {
		buff := make([]byte, 20)

		for {
			n, err := ss.Read(buff)

			if err != nil {
				fmt.Println("Read by server err:", err)
				break
			}

			fmt.Println("-- Server received:", buff[:n])

			ss.Write([]byte("Cool"))
		}
	}()

	cc.Write([]byte("hi"))

	buff := make([]byte, 20)

	n, err := cc.Read(buff)

	if err != nil {
		fmt.Println("Read by client err:", err)
		return
	}

	fmt.Println("-- Client received:", buff[:n])
}

Documentation

Index

Constants

View Source
const (
	ALGO_AES256_GCM    uint8  = 1
	ALGO_AES128_GCM    uint8  = 2
	DEFAULT_CHUNK_SIZE uint16 = 32 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	net.Conn

	Encrypt(p []byte) (d []byte, err error)
	Decrypt(p []byte) (d []byte, err error)
}

func New

func New(c net.Conn, opts *Opts) (Conn, error)

type Opts

type Opts struct {
	Algo uint8
	Key  []byte
	Size uint16 // Max chunk size.
}

Jump to

Keyboard shortcuts

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