Giter Club home page Giter Club logo

symcrypto's Introduction

symcrypto

Build Status Coverage Status GoDoc Go Report Card

A URL safe, string encryption/decryption library.

Encryption and decryption is done using a secret key. secretbox is used under the hood.

Install

# using dep(recommended)
$ dep ensure -add github.com/sudo-suhas/symcrypto

# using go get
$ go get -u github.com/sudo-suhas/symcrypto

Usage

package main

import (
	"fmt"

	"github.com/sudo-suhas/symcrypto"
)

func handleError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	// Load your secret key from a safe place and use it to create an instance of
	// `Crypter`. (Obviously don't use this example key for anything real.) If you want
	// to convert a passphrase to a key, use a suitable package like bcrypt or scrypt.
	crypto, err := symcrypto.New("6368616e676520746869732070617373")
	handleError(err)

	// This returns the nonce appended with the encrypted string for "hello world".
	encrypted, err := crypto.Encrypt("hello world")
	handleError(err)

	fmt.Printf("Encrypted message - %q\n", encrypted)
	// Output: Encrypted message - "2eUERfII6K7djr-GCR2qwSf8LJ-7ZoOmdlT54HPkhw297ML46M6VvlpvW2LrA_Ewge-2"
	// Because of unique nonce, encrypted message will vary for the same input.

	// The encrypted string can be decrypted only by using the `Crypter` instance which
	// was used to encrypt it.
	decrypted, err := crypto.Decrypt(encrypted)
	handleError(err)

	fmt.Printf("Decrypted message - %q\n", decrypted)
	// Output: Decrypted message - "hello world"
}

License

MIT © Suhas Karanth

symcrypto's People

Contributors

sudo-suhas avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

sparklive

symcrypto's Issues

what is the usage scenario of this package

thank you for sharing.

The encrypted string can be decrypted only by using the Crypter instance which was used to encrypt it. So what is the usage scenario of this package?

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.