Created
February 24, 2021 02:58
-
-
Save databeast/dabdb01abc678e9998bb38735647d7fa to your computer and use it in GitHub Desktop.
lambda password hasher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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