Code Monkey home page Code Monkey logo

go's Introduction

go packages

Coverage Status MIT License API Reference Go Report Card

cnigma
random

cnigma

The golang implementation of cnigma

Usage

go get github.com/keng42/go/cnigma

AES

import (
	"fmt"
	"log"

	"github.com/keng42/go/cnigma/aes"
	"github.com/keng42/go/cnigma/aes/types"
)

func main() {
	aesgcm, err := NewAES(types.ModeGCM, types.DefaultKey, "my-password", types.Base64)
	if err != nil {
		log.Fatal(err)
	}

	ciphertext, err := aesgcm.EncryptText("hello world @ 2020", "")
	if err != nil {
		log.Fatal(err)
	}

	plaintext, err := aesgcm.DecryptText(ciphertext, "")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(plaintext)
	// Output: hello world @ 2020
}

RSA

import (
	"fmt"
	"log"

	"github.com/keng42/go/cnigma/rsa"
	"github.com/keng42/go/cnigma/rsa/types"
)

func main() {
	priv, err := rsa.LoadPrivateKey("../testdata/rsa-private-pkcs8.key")
	if err != nil {
		log.Fatal(err)
	}

	r, _ := rsa.NewRSA(types.Hex)
	r.PrivateKey = priv
	r.PublicKey = &priv.PublicKey

	msg := "hello world @ 2020"

	// Sign message with private key
	sig, err := r.Sign(msg)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("sig", sig)

	// Verify message with public key
	verified, err := r.Verify(msg, sig)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("verified", verified)

	// Encrypt text with public key
	ciphertext, err := r.Encrypt(msg)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("ciphertext", ciphertext)

	// Decrypt text with private key
	plaintext, err := r.Decrypt(ciphertext)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("plaintext", plaintext)
}

random

A simple app for generating random strings.

Usage

go install github.com/keng42/go/cmd/random

random

Example output:

hex
16 e6490cd6bb281fde
32 4a569b71d9e49b00454bd6b6d72073e0
64 09f34cfe26a3d4589bfff3220c3025331f7987793f3d433e87f7351ddc4317f5

base64
16 MoXXjCtj0xauGwo6
32 cKoWekLvPCBnEItEkd16GujjycUyV7yE
64 zv6dZHby9uZQKXCr72IL75yDQc6MzSBkM4J9StPAeWQIUZTmDSApmVEWQxzXYbZu

ascii
16 M#7A!->jt48N>`!G
32 QJOl6XJZAdk^E&9''3+;CO?r*?YnYXe_
64 ,B(i<,O<.C@SJYEjK=c)h6(Mh#C>8RUJUKS2QbWa>l`Mm't>\opMmN<o,Ac4OAZA

go's People

Contributors

keng42 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.