fernet / fernet-go Goto Github PK
View Code? Open in Web Editor NEWFernet generates and verifies HMAC-based authentication tokens.
Home Page: http://godoc.org/github.com/fernet/fernet-go
License: MIT License
Fernet generates and verifies HMAC-based authentication tokens.
Home Page: http://godoc.org/github.com/fernet/fernet-go
License: MIT License
Fernet takes a user-provided *message* (an arbitrary sequence of bytes), a *key* (256 bits), and the current time, and produces a *token*, which contains the message in a form that can't be read or altered without the key. This package is compatible with the other implementations at https://github.com/fernet. They can exchange tokens freely among each other. Documentation: http://godoc.org/github.com/fernet/fernet-go INSTALL $ go get github.com/fernet/fernet-go For more information and background, see the Fernet spec at https://github.com/fernet/spec. Fernet is distributed under the terms of the MIT license. See the License file for details.
I am attempting to build a simple ruby script that will encrypt_and_sign data that kr/fernet can read.
There seems to be something wrong with my implementation. Any pointers you can provide would be greatly appreciated.
Adding FernetReader
and FernetWriter
implementing io.Reader
and io.Writer
would be really helpful and avoid tinkering with []byte
.
package main
import (
"fmt"
"time"
"github.com/fernet/fernet-go"
)
func main() {
a := []byte{103, 71, 70, 105, 89, 119, 61, 61}
keys := fernet.MustDecodeKeys("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
fmt.Println(fernet.VerifyAndDecrypt(a, time.Second * 60, keys))
}
I've noticed that encrypted payloads are base64 coded. Does it make any sense to have a binary mode? I'd like to use Fernet in a high-volume way (maybe that's against design ethos, I am not sure) and avoid paying for base64 in size blowup if possible.
I expected that when I provide a string input s to fernet for decoding, that I can take the resulting key and encode it to be s' and I should find that s' is equal to s.
Here is a sample program that demonstrates that what I expect is not what actually happens:
Fernet Version:
$ cd $GOPATH/src/github.com/kr/fernet
$ git log -1 --pretty=%h
9596341
Go Version:
$ go version
go version go1.1.1 darwin/amd64
Program:
package main
import (
"fmt"
"github.com/kr/fernet"
)
func main() {
s := "BecstsYSkJY33Us91kgl6qPubHowWXcqaBxqhu7Nu6_="
k := fernet.MustDecodeKeys(s)
fmt.Printf("s=%s\ns'=%s\n", s, k[0].Encode())
}
Result:
$ go run x.go
s =BecstsYSkJY33Us91kgl6qPubHowWXcqaBxqhu7Nu6_=
s'=BecstsYSkJY33Us91kgl6qPubHowWXcqaBxqhu7Nu68=
This had me pulling hair for a while, but it seems that, if a different key is used to decrypt a token than is used to create it, even if they have the same secret, it will fail. Unfortunately, this means I cannot use fernet across servers.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.