forked from mtusi2026/mtusi2026lab2
36 lines
786 B
Go
36 lines
786 B
Go
package provider
|
|
|
|
import (
|
|
"crypto/rsa"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
)
|
|
|
|
func readPrivateKeyFromFile(path string) (*rsa.PrivateKey, error) {
|
|
key, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read public key: %w", err)
|
|
}
|
|
|
|
privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse private key: %w", err)
|
|
}
|
|
return privateKey, nil
|
|
}
|
|
|
|
func readPublicKeyFromFile(path string) (*rsa.PublicKey, error) {
|
|
key, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read public key: %w", err)
|
|
}
|
|
|
|
privateKey, err := jwt.ParseRSAPublicKeyFromPEM(key)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse private key: %w", err)
|
|
}
|
|
return privateKey, nil
|
|
}
|