Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
846 B
1
Indexable
Never
package main

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

func generateCodeVerifier(codeChallenge string) (string, error) {
	// Decode the base64-encoded code challenge
	challengeBytes, err := base64.URLEncoding.DecodeString(codeChallenge)
	if err != nil {
		return "", err
	}

	// Encode the decoded bytes to base64
	codeVerifier := base64.URLEncoding.EncodeToString(challengeBytes)

	return codeVerifier, nil
}

func main() {
	// Example code challenge (replace this with your actual code challenge)
	codeChallenge := "exampleCodeChallenge123"

	// Generate code verifier from the code challenge
	codeVerifier, err := generateCodeVerifier(codeChallenge)
	if err != nil {
		fmt.Println("Error generating code verifier:", err)
		return
	}

	// Print the generated code verifier
	fmt.Println("Generated Code Verifier:", codeVerifier)
}
Leave a Comment