alirasoli / go-phpencryption

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-phpencryption

This is go implementation of https://github.com/defuse/php-encryption which is used in league/oauth2-server in PHP/Symfony.

How to use

Add the package to your project:

go get github.com/alirasoli/go-phpencryption
package main

import (
	"fmt"
	"log"

	"github.com/alirasoli/go-phpencryption"
)

const encryptionKey = "key"
const data = "datatoencrypt"

func main() {
	p := phpencryption.NewPHPEncryption([]byte(encryptionKey))
	
	encrypted, err := p.Encrypt([]byte(data))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(encrypted)

	decrypted, err := p.Decrypt(encrypted)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(decrypted))
}

About


Languages

Language:Go 100.0%