Initial commit

This commit is contained in:
2019-02-03 20:56:58 +01:00
commit 2a8a20195a
30 changed files with 1595 additions and 0 deletions

25
crypto/pem.go Normal file
View 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)
}