Skip to content

Instantly share code, notes, and snippets.

@databeast
Created February 24, 2021 02:58
Show Gist options
  • Save databeast/dabdb01abc678e9998bb38735647d7fa to your computer and use it in GitHub Desktop.
Save databeast/dabdb01abc678e9998bb38735647d7fa to your computer and use it in GitHub Desktop.
lambda password hasher
package main
import (
"context"
"crypto/sha256"
"encoding/base64"
"github.com/aws/aws-lambda-go/lambda"
"golang.org/x/crypto/pbkdf2"
)
type hashRequest struct {
Password string `json:"password"`
Salt string `json:"salt"`
Iterations int `json:"iterations"`
}
type hashResponse struct {
DK string `json:"dk"`
}
func HandleRequest(ctx context.Context, request hashRequest) (*hashResponse, error) {
hashed := pbkdf2.Key([]byte(request.Password), []byte(request.Salt), request.Iterations, sha256.Size, sha256.New)
return &hashResponse{
DK: base64.StdEncoding.EncodeToString(hashed),
}, nil
}
func main() {
lambda.Start(HandleRequest)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment