Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
736 B
2
Indexable
Never
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)
}
Leave a Comment