package encrypter import ( "crypto/x509" "encoding/base64" ) // EncryptedPrivateKey type type EncryptedPrivateKey []byte // DecryptKey func func (s *EncryptedPrivateKey) DecryptKey(key *PrivateKey) (*PrivateKey, error) { bb, err := key.Decrypt(([]byte)(*s)) if err != nil { return nil, err } k, err := x509.ParsePKCS1PrivateKey(bb) if err != nil { return nil, err } return (*PrivateKey)(k), nil } // MarshalJSON func func (s *EncryptedPrivateKey) MarshalJSON() ([]byte, error) { return []byte("\"" + base64.RawURLEncoding.EncodeToString(([]byte)(*s)) + "\""), nil } func (s *EncryptedPrivateKey) String() string { return base64.RawURLEncoding.EncodeToString(*s) }