forked from github/dynamiclistener
Use chinese crypto
This commit is contained in:
25
cert/pem.go
25
cert/pem.go
@@ -41,7 +41,7 @@ const (
|
||||
)
|
||||
|
||||
// EncodePublicKeyPEM returns PEM-encoded public data
|
||||
func EncodePublicKeyPEM(key *rsa.PublicKey) ([]byte, error) {
|
||||
func EncodePublicKeyPEM(key interface{}) ([]byte, error) {
|
||||
der, err := x509.MarshalPKIXPublicKey(key)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
@@ -54,12 +54,25 @@ func EncodePublicKeyPEM(key *rsa.PublicKey) ([]byte, error) {
|
||||
}
|
||||
|
||||
// EncodePrivateKeyPEM returns PEM-encoded private key data
|
||||
func EncodePrivateKeyPEM(key *rsa.PrivateKey) []byte {
|
||||
block := pem.Block{
|
||||
Type: RSAPrivateKeyBlockType,
|
||||
Bytes: x509.MarshalPKCS1PrivateKey(key),
|
||||
func EncodePrivateKeyPEM(key interface{}) []byte {
|
||||
var block *pem.Block
|
||||
switch privKey := key.(type) {
|
||||
case *ecdsa.PrivateKey:
|
||||
derBytes, _ := x509.MarshalECPrivateKey(privKey)
|
||||
block = &pem.Block{
|
||||
Type: ECPrivateKeyBlockType,
|
||||
Bytes: derBytes,
|
||||
}
|
||||
case *rsa.PrivateKey:
|
||||
block = &pem.Block{
|
||||
Type: RSAPrivateKeyBlockType,
|
||||
Bytes: x509.MarshalPKCS1PrivateKey(privKey),
|
||||
}
|
||||
}
|
||||
return pem.EncodeToMemory(&block)
|
||||
if block != nil {
|
||||
return pem.EncodeToMemory(block)
|
||||
}
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
// EncodeCertPEM returns PEM-endcoded certificate data
|
||||
|
Reference in New Issue
Block a user