Git Product home page Git Product logo

rncryptor-go's Introduction

RNCryptor-go

Go implementation of RNCryptor.

What is RNCryptor?

RNCryptor is a data format specificiation for AES encryption, with AES-256, random-salted PBKDF2, AES-CBC, random IV, and HMAC. It has implementations in several languages.

You can head over to the RNCryptor website for more information, or checkout the GitHub Organization for implementations in other languages.

Installation

go get github.com/RNCryptor/RNCryptor-go

Example

package main

import(
  "fmt"
  "github.com/RNCryptor/RNCryptor-go"
)

func main() {
  pass := "test"
  data := []byte("hello world")

  fmt.Printf("source: %v\n", string(data))

  encrypted, _ := rncryptor.Encrypt(pass, data)
  fmt.Printf("encrypted: %v\n", string(encrypted))

  // if you need to send the encrypted data across
  // the wire, you'll probably want to call
  // `base64.StdEncoding.EncodeToString(encrypted)`
  // to base64 the data rather than transmiting raw bytes

  decrypted, _ := rncryptor.Decrypt(pass, encrypted)
  fmt.Printf("decrypted: %v\n", string(decrypted))
}

API

Encrypt(password string, data []byte) ([]byte, error)

Encrypts data using password. Automatically handles salting, iv-generation, and hmac signing. Returns the decrypted data, or an error, if encryption was unsuccessful.

  • Password must be at least 1 character long.
encrypted, err := rncryptor.Encrypt("securepassword", []byte("bytes to encrypt"))
if err != nil {
  log.Printf("error encrypting data: %v", err)
}

// from here, you can encode `encrypted` however you want
// base64.StdEncoding.EncodeToString(encrypted)

Decrypt(password string, data []byte) ([]byte, error)

Decrypts data using password. Returns un-encrypted data, or an error if decryption is unsuccessful (e.g. password mismatch).

  • Password must match the password used during encryption
// if the encrypted data has been encoded, you'll need to decode it first
// base64.StdEncoding.DecodeString("base64data")

decrypted, err := rncryptor.Decrypt("securepassword", []byte("encrypted bytes"))
if err != nil {
  log.Printf("error decrypting data: %v", err)
}

Notes

If you'd like to help with any of the items below, send a pull-request!

Contributing

Please read over GitHub's guide on contributing if you'd like to lend a hand!

Credits

Thanks to Rob Napier and the maintainers of the various RNCryptor implementations for all their hard work!

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.