Documentation ¶
Index ¶
- Variables
- func Decrypt(priv *PrivateKey, cipher1, cipher2 []byte) ([]byte, error)
- func DecryptAsn1(priv *PrivateKey, cipherData []byte) ([]byte, error)
- func Encrypt(random io.Reader, pub *PublicKey, message []byte) ([]byte, []byte, error)
- func EncryptAsn1(random io.Reader, pub *PublicKey, message []byte) ([]byte, error)
- func GeneratePQZp(random io.Reader, n, probability int) (*big.Int, *big.Int, *big.Int, error)
- func MarshalPKCS1PrivateKey(key *PrivateKey) ([]byte, error)
- func MarshalPKCS1PublicKey(key *PublicKey) ([]byte, error)
- func MarshalPKCS8PrivateKey(key *PrivateKey) ([]byte, error)
- func MarshalPKCS8PublicKey(pub *PublicKey) ([]byte, error)
- func MarshalXMLPrivateKey(key *PrivateKey) ([]byte, error)
- func MarshalXMLPublicKey(key *PublicKey) ([]byte, error)
- func Sign(rand io.Reader, priv *PrivateKey, hash []byte) ([]byte, []byte, error)
- func SignASN1(rand io.Reader, priv *PrivateKey, hash []byte) ([]byte, error)
- func Verify(pub *PublicKey, hash, r, s []byte) (bool, error)
- func VerifyASN1(pub *PublicKey, hash, sig []byte) (bool, error)
- type PKCS1Key
- type PKCS8Key
- type PrivateKey
- func (priv *PrivateKey) Decrypt(cipher1, cipher2 []byte) ([]byte, error)
- func (priv *PrivateKey) DecryptAsn1(cipherData []byte) ([]byte, error)
- func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *PrivateKey) Public() crypto.PublicKey
- func (priv *PrivateKey) Sign(random io.Reader, hash []byte) ([]byte, []byte, error)
- type PublicKey
- func (pub *PublicKey) Encrypt(random io.Reader, message []byte) ([]byte, []byte, error)
- func (pub *PublicKey) EncryptAsn1(random io.Reader, message []byte) ([]byte, error)
- func (pub *PublicKey) Equal(x crypto.PublicKey) bool
- func (pub *PublicKey) HommorphicEncMultiple(ciphertext [][2][]byte) ([]byte, []byte, error)
- func (pub *PublicKey) HomomorphicEncTwo(c1, c2, c1dash, c2dash []byte) ([]byte, []byte, error)
- func (pub *PublicKey) Verify(hash, r, s []byte) (bool, error)
- type XMLKey
Constants ¶
This section is empty.
Variables ¶
var ( // 默认为 pkcs1 模式 MarshalPublicKey = MarshalPKCS1PublicKey ParsePublicKey = ParsePKCS1PublicKey MarshalPrivateKey = MarshalPKCS1PrivateKey ParsePrivateKey = ParsePKCS1PrivateKey )
var ErrCipherLarge = errors.New("elgamal: cipher is larger than public key size")
var ErrMessageLarge = errors.New("elgamal: message is larger than public key size")
Functions ¶
func Decrypt ¶ added in v1.0.2019
func Decrypt(priv *PrivateKey, cipher1, cipher2 []byte) ([]byte, error)
解密
func DecryptAsn1 ¶ added in v1.0.2019
func DecryptAsn1(priv *PrivateKey, cipherData []byte) ([]byte, error)
解密 Asn1
func EncryptAsn1 ¶ added in v1.0.2019
加密 Asn1
func GeneratePQZp ¶
Gen emit <p,q,g>. p = 2q + 1, p,q - safe primes g - cyclic group generator Zp performs n Miller-Rabin tests with 1 - 1/(4^n) probability false rate. Gain n - bit width for integer & probability rang for MR. It returns p, q, g and write error message.
func MarshalPKCS8PrivateKey ¶
func MarshalPKCS8PrivateKey(key *PrivateKey) ([]byte, error)
PKCS8 包装私钥
func MarshalXMLPrivateKey ¶
func MarshalXMLPrivateKey(key *PrivateKey) ([]byte, error)
func MarshalXMLPublicKey ¶
Types ¶
type PKCS1Key ¶
type PKCS1Key struct{}
*
- elgamal pkcs1 密钥 *
- @create 2023-6-16
- @author deatil
func (PKCS1Key) MarshalPrivateKey ¶
func (this PKCS1Key) MarshalPrivateKey(key *PrivateKey) ([]byte, error)
包装私钥
func (PKCS1Key) MarshalPublicKey ¶
包装公钥
func (PKCS1Key) ParsePrivateKey ¶
func (this PKCS1Key) ParsePrivateKey(der []byte) (*PrivateKey, error)
解析私钥
type PKCS8Key ¶
type PKCS8Key struct{}
*
- elgamal pkcs8 密钥 *
- @create 2023-6-16
- @author deatil
func (PKCS8Key) MarshalPrivateKey ¶
func (this PKCS8Key) MarshalPrivateKey(key *PrivateKey) ([]byte, error)
PKCS8 包装私钥
func (PKCS8Key) MarshalPublicKey ¶
PKCS8 包装公钥
func (PKCS8Key) ParsePrivateKey ¶
func (this PKCS8Key) ParsePrivateKey(der []byte) (key *PrivateKey, err error)
PKCS8 解析私钥
type PrivateKey ¶
PrivateKey represents Elgamal private key.
func GenerateKey ¶
func GenerateKey(random io.Reader, bitsize, probability int) (*PrivateKey, error)
GenerateKey generates elgamal private key according to given bit size and probability. Moreover, the given probability value is used in choosing prime number P for performing n Miller-Rabin tests with 1 - 1/(4^n) probability false rate.
func ParsePKCS8PrivateKey ¶
func ParsePKCS8PrivateKey(derBytes []byte) (key *PrivateKey, err error)
PKCS8 解析私钥
func ParseXMLPrivateKey ¶
func ParseXMLPrivateKey(der []byte) (*PrivateKey, error)
func (*PrivateKey) Decrypt ¶
func (priv *PrivateKey) Decrypt(cipher1, cipher2 []byte) ([]byte, error)
Decrypt decrypts the passed cipher text. It returns an error if cipher text value is larger than modulus P of Public key.
func (*PrivateKey) DecryptAsn1 ¶
func (priv *PrivateKey) DecryptAsn1(cipherData []byte) ([]byte, error)
Decrypt decrypts the passed cipher text.
func (*PrivateKey) Equal ¶
func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
Equal reports whether priv and x have the same value.
func (*PrivateKey) Public ¶
func (priv *PrivateKey) Public() crypto.PublicKey
Public returns the public key corresponding to priv.
type PublicKey ¶
PublicKey represents a Elgamal public key.
func ParseXMLPublicKey ¶
func (*PublicKey) Encrypt ¶
Encrypt encrypts a plain text represented as a byte array. It returns an error if plain text value is larger than modulus P of Public key.
func (*PublicKey) EncryptAsn1 ¶
Encrypt encrypts a plain text represented as a byte array.
func (*PublicKey) HommorphicEncMultiple ¶
HommorphicEncMultiple performs homomorphic operation over multiple passed chiphers. Elgamal has multiplicative homomorphic property, so resultant cipher contains the product of multiple numbers.
func (*PublicKey) HomomorphicEncTwo ¶
HomomorphicEncTwo performs homomorphic operation over two passed chiphers. Elgamal has multiplicative homomorphic property, so resultant cipher contains the product of two numbers.
type XMLKey ¶
type XMLKey struct{}
*
- elgamal xml密钥 *
- @create 2023-6-16
- @author deatil
func (XMLKey) MarshalPrivateKey ¶
func (this XMLKey) MarshalPrivateKey(key *PrivateKey) ([]byte, error)
包装私钥
func (XMLKey) MarshalPublicKey ¶
包装公钥
func (XMLKey) ParsePrivateKey ¶
func (this XMLKey) ParsePrivateKey(data []byte) (*PrivateKey, error)
解析私钥