Untitled

 avatar
unknown
plain_text
2 years ago
736 B
5
Indexable
package main

import (
	"crypto/sha256"
	"encoding/base64"
	"fmt"
)

func generateCodeChallenge(codeVerifier string) string {
	// Convert codeVerifier to bytes
	verifierBytes := []byte(codeVerifier)

	// Hash the codeVerifier using SHA-256
	hasher := sha256.New()
	hasher.Write(verifierBytes)
	hashedBytes := hasher.Sum(nil)

	// Encode the hashed bytes to base64
	codeChallenge := base64.RawURLEncoding.EncodeToString(hashedBytes)

	return codeChallenge
}

func main() {
	// Example code verifier
	codeVerifier := "exampleCodeVerifier"

	// Generate code challenge
	codeChallenge := generateCodeChallenge(codeVerifier)

	// Print the result
	fmt.Println("Code Verifier:", codeVerifier)
	fmt.Println("Code Challenge:", codeChallenge)
}
Editor is loading...
Leave a Comment