GithubHelp home page GithubHelp logo

goprocrypt's Introduction

goprocrypt

Simple Go RSA Asymmetric Key Encryption for Protocol Buffers

dependency

dep ensure -add "github.com/Yomiji/goprocrypt"

protocol

Provided EncryptedMessage protocol buffer is returned from an encrypted message. The EncryptedMessage protocol buffer has the following configuration:

syntax = "proto3";
package goprocrypt;
option go_package = "goprocrypt";

message EncryptedMessage {
    bytes id = 1; //hash of type
    bytes signature = 3;
    bytes digest = 5;
}

The idea is that an application would encrypt, send and then decrypt an EncryptedMessage protocol buffer. An application could use the id parameter to hash the protocol buffer's specific type.

useage

import (
	"github.com/Yomiji/genrsa"
	"github.com/Yomiji/goprocrypt"
	"github.com/golang/protobuf/proto"
	"testing"
	"time"
)

var party1private, party1public = genrsa.MakeKeys(2048)
var party2private, party2public = genrsa.MakeKeys(2048)

var testMsg = &TestMsg{
  Time:time.Now().Unix(),
  TrialNo:0,
  Msgtext:"Some Text",
}

func TestEncrypt(t *testing.T) {
	// private key necessary for signature application from first party, encrypting for second party
	encMsg, err := goprocrypt.Encrypt([]byte("test"), testMsg, party2public, party1private)
	
	// do something with encrypted message
}

func TestDecrypt(t *testing.T) {
	decMsg := &TestMsg{}

	encMsg, err := goprocrypt.Encrypt([]byte("test"), testMsg, party2public, party1private)
	
	// first party's public key for verification of identity and second party key for decryption
	// directly modifies decMsg to fill it with the decrypted data, the type must match or an error
	// occurs
	err = goprocrypt.Decrypt([]byte("test"), encMsg, party2private, party1public, decMsg)
	
	// do something with decMsg, which now contains testMsg unencrypted
}

To change the encryption algorithm:

goprocrypt.Hash = crypto.SHA256

To change the verification algorithm:

goprocrypt.Sign = crypto.SHA512_256

goprocrypt's People

Contributors

yomiji avatar dtechsnow avatar

Watchers

James Cloos 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.