@@ -11,6 +11,7 @@ import (
1111 "github.com/deatil/go-cryptobin/pkcs8"
1212 "github.com/deatil/go-cryptobin/gm/sm2"
1313 "github.com/deatil/go-cryptobin/pubkey/gost"
14+ "github.com/deatil/go-cryptobin/pubkey/elgamal"
1415 cryptobin_x509 "github.com/deatil/go-cryptobin/x509"
1516 pubkey_dsa "github.com/deatil/go-cryptobin/pubkey/dsa"
1617)
@@ -23,15 +24,17 @@ var (
2324)
2425
2526var (
26- oidPublicKeySM2 = asn1.ObjectIdentifier {1 , 2 , 156 , 10197 , 1 , 301 }
2727 oidPublicKeyRSA = asn1.ObjectIdentifier {1 , 2 , 840 , 113549 , 1 , 1 , 1 }
2828 oidPublicKeyDSA = asn1.ObjectIdentifier {1 , 2 , 840 , 10040 , 4 , 1 }
2929 oidPublicKeyECDSA = asn1.ObjectIdentifier {1 , 2 , 840 , 10045 , 2 , 1 }
3030 oidPublicKeyEd25519 = asn1.ObjectIdentifier {1 , 3 , 101 , 112 }
31+ oidPublicKeySM2 = asn1.ObjectIdentifier {1 , 2 , 156 , 10197 , 1 , 301 }
32+
33+ oidGOSTPublicKey = asn1.ObjectIdentifier {1 , 2 , 643 , 2 , 2 , 19 }
34+ oidGost2012PublicKey256 = asn1.ObjectIdentifier {1 , 2 , 643 , 7 , 1 , 1 , 1 , 1 }
35+ oidGost2012PublicKey512 = asn1.ObjectIdentifier {1 , 2 , 643 , 7 , 1 , 1 , 1 , 2 }
3136
32- oidGOSTPublicKey = asn1.ObjectIdentifier {1 , 2 , 643 , 2 , 2 , 19 }
33- oidGost2012PublicKey256 = asn1.ObjectIdentifier {1 , 2 , 643 , 7 , 1 , 1 , 1 , 1 }
34- oidGost2012PublicKey512 = asn1.ObjectIdentifier {1 , 2 , 643 , 7 , 1 , 1 , 1 , 2 }
37+ oidPublicKeyElGamal = asn1.ObjectIdentifier {1 , 3 , 6 , 1 , 4 , 1 , 3029 , 1 , 2 , 1 }
3538)
3639
3740type pkcs8Info struct {
@@ -89,6 +92,8 @@ func (this CA) ParsePKCS8PrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error
8992 privKey .Algo .Algorithm .Equal (oidGost2012PublicKey256 ),
9093 privKey .Algo .Algorithm .Equal (oidGost2012PublicKey512 ):
9194 parsedKey , err = gost .ParsePrivateKey (block .Bytes )
95+ case privKey .Algo .Algorithm .Equal (oidPublicKeyElGamal ):
96+ parsedKey , err = elgamal .ParsePKCS8PrivateKey (block .Bytes )
9297 default :
9398 return nil , ErrPrivateKeyError
9499 }
@@ -148,6 +153,8 @@ func (this CA) ParsePKCS8PrivateKeyFromPEMWithPassword(key []byte, password []by
148153 privKey .Algo .Algorithm .Equal (oidGost2012PublicKey256 ),
149154 privKey .Algo .Algorithm .Equal (oidGost2012PublicKey512 ):
150155 parsedKey , err = gost .ParsePrivateKey (blockDecrypted )
156+ case privKey .Algo .Algorithm .Equal (oidPublicKeyElGamal ):
157+ parsedKey , err = elgamal .ParsePKCS8PrivateKey (blockDecrypted )
151158 default :
152159 return nil , ErrPrivateKeyError
153160 }
@@ -202,6 +209,8 @@ func (this CA) ParsePKCS8PublicKeyFromPEM(key []byte) (crypto.PublicKey, error)
202209 pubkey .Algo .Algorithm .Equal (oidGost2012PublicKey256 ),
203210 pubkey .Algo .Algorithm .Equal (oidGost2012PublicKey512 ):
204211 parsedKey , err = gost .ParsePublicKey (block .Bytes )
212+ case pubkey .Algo .Algorithm .Equal (oidPublicKeyElGamal ):
213+ parsedKey , err = elgamal .ParsePKCS8PublicKey (block .Bytes )
205214 default :
206215 return nil , ErrPublicKeyError
207216 }
0 commit comments