github.com/Axway/agent-sdk@v1.1.101/pkg/authz/oauth/keyreader.go (about) 1 package oauth 2 3 import ( 4 "crypto/rsa" 5 6 "github.com/Axway/agent-sdk/pkg/util" 7 ) 8 9 type KeyReader interface { 10 GetPrivateKey() (*rsa.PrivateKey, error) 11 GetPublicKey() ([]byte, error) 12 } 13 14 type keyReader struct { 15 privKey string // path to rsa encoded private key, used to sign platform tokens 16 publicKey string // path to the rsa encoded public key 17 password string // path to password for private key 18 } 19 20 func NewKeyReader(privateKey, publicKey, password string) KeyReader { 21 return &keyReader{ 22 privKey: privateKey, 23 publicKey: publicKey, 24 password: password, 25 } 26 } 27 28 func (kr *keyReader) GetPrivateKey() (*rsa.PrivateKey, error) { 29 return util.ReadPrivateKeyFile(kr.privKey, kr.password) 30 } 31 32 // getPublicKey from the path provided 33 func (kr *keyReader) GetPublicKey() ([]byte, error) { 34 return util.ReadPublicKeyBytes(kr.publicKey) 35 }