Skip to content

Mystery00/go-jasypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-jasypt

GoLang implements jasypt encryption and decryption

How to use

  1. you need to import jasypt package:
go get -u github.com/Mystery00/go-jasypt
  1. use like this:
package jasypt

import (
	"github.com/Mystery00/go-jasypt"
	"github.com/Mystery00/go-jasypt/iv"
	"github.com/Mystery00/go-jasypt/salt"
)

const (
	// specify the algorithm
	algorithm = "PBEWithHMACSHA512AndAES_256"
	// specify the password
	password = "password"
)

func Encrypt(message string) (string, error) {
	// create a new instance of jasypt
	encryptor := jasypt.New(algorithm, jasypt.NewConfig(
		jasypt.SetPassword(password),
		jasypt.SetSaltGenerator(salt.RandomSaltGenerator{}),
		jasypt.SetIvGenerator(iv.RandomIvGenerator{}),
	))
	// encrypt the message
	return encryptor.Encrypt(message)
}

func Decrypt(encode string) (string, error) {
	// create a new instance of jasypt
	encryptor := jasypt.New(algorithm, jasypt.NewConfig(
		jasypt.SetPassword(password),
		jasypt.SetSaltGenerator(salt.RandomSaltGenerator{}),
		jasypt.SetIvGenerator(iv.RandomIvGenerator{}),
	))
	// decrypt the message
	return encryptor.Decrypt(encode)
}