Documentation ¶
Index ¶
- Variables
- func Decrypt(priv *PrivateKey, c1, c2 *big.Int) (msg []byte, err error)
- func DecryptASN1(priv *PrivateKey, cipherData []byte) ([]byte, error)
- func DecryptLegacy(priv *PrivateKey, c1, c2 *big.Int) (msg []byte, err error)
- func Encrypt(random io.Reader, pub *PublicKey, msg []byte) (c1, c2 *big.Int, err error)
- func EncryptASN1(random io.Reader, pub *PublicKey, message []byte) ([]byte, error)
- func EncryptLegacy(random io.Reader, pub *PublicKey, msg []byte) (c1, c2 *big.Int, err error)
- func GeneratePQZp(random io.Reader, n, probability int) (*big.Int, *big.Int, *big.Int, error)
- func HommorphicEncMultiple(pub *PublicKey, ciphertext [][2][]byte) (*big.Int, *big.Int, error)
- func HomomorphicEncTwo(pub *PublicKey, c1, c2, c1dash, c2dash []byte) (*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(random io.Reader, priv *PrivateKey, hash []byte) (*big.Int, *big.Int, error)
- func SignASN1(rand io.Reader, priv *PrivateKey, hash []byte) ([]byte, error)
- func Verify(pub *PublicKey, hash []byte, r, s *big.Int) (bool, error)
- func VerifyASN1(pub *PublicKey, hash, sig []byte) (bool, error)
- type PKCS1Key
- type PKCS8Key
- type PrivateKey
- func (priv *PrivateKey) Decrypt(random io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
- func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *PrivateKey) Public() crypto.PublicKey
- func (priv *PrivateKey) Sign(random io.Reader, hash []byte, opts crypto.SignerOpts) (signature []byte, err error)
- type PublicKey
- 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, c1, c2 *big.Int) (msg []byte, err error)
Decrypt
func DecryptASN1 ¶ added in v1.0.2039
func DecryptASN1(priv *PrivateKey, cipherData []byte) ([]byte, error)
Decrypt Asn1
func DecryptLegacy ¶ added in v1.0.2054
func DecryptLegacy(priv *PrivateKey, c1, c2 *big.Int) (msg []byte, err error)
DecryptLegacy
func EncryptASN1 ¶ added in v1.0.2039
Encrypt Asn1
func EncryptLegacy ¶ added in v1.0.2054
EncryptLegacy
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 HommorphicEncMultiple ¶ added in v1.0.2039
HommorphicEncMultiple performs homomorphic operation over multiple passed chiphers. Elgamal has multiplicative homomorphic property, so resultant cipher contains the product of multiple numbers.
func HomomorphicEncTwo ¶ added in v1.0.2039
HomomorphicEncTwo performs homomorphic operation over two passed chiphers. Elgamal has multiplicative homomorphic property, so resultant cipher contains the product of two numbers.
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(random io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err 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) 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.
func (*PrivateKey) Sign ¶
func (priv *PrivateKey) Sign(random io.Reader, hash []byte, opts crypto.SignerOpts) (signature []byte, err error)
Signature generates signature over the given hash. It returns signature value consisting of two parts "r" and "s" as byte arrays.
type PublicKey ¶
PublicKey represents a Elgamal public key.
func ParseXMLPublicKey ¶
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)
解析私钥