Initial commit
This commit is contained in:
25
crypto/pem.go
Normal file
25
crypto/pem.go
Normal file
@ -0,0 +1,25 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
func EncodePublicKeyToPEM(key interface{}) ([]byte, error) {
|
||||
pub, err := x509.MarshalPKIXPublicKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data := pem.EncodeToMemory(&pem.Block{
|
||||
Type: "PUBLIC KEY",
|
||||
Bytes: pub,
|
||||
})
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func DecodePEMToPublicKey(pem []byte) (*rsa.PublicKey, error) {
|
||||
return jwt.ParseRSAPublicKeyFromPEM(pem)
|
||||
}
|
Reference in New Issue
Block a user