Documentation
¶
Index ¶
- type AbstractMode
- type Aes
- type AesMode
- type CryptoPaddingEnum
- type FormatEnum
- type HashTypeEnum
- type KeyFormatEnum
- type PaddingEnum
- type PemTypeEnum
- type Rsa
- func (r *Rsa) BuildCert(template, parentCert *x509.Certificate, parentPrivateKey *rsa.PrivateKey) error
- func (r *Rsa) Decrypt(ciphertext string, padding CryptoPaddingEnum, hashType HashTypeEnum, ...) (plainText []byte, err error)
- func (r *Rsa) Encrypt(plainText []byte, padding CryptoPaddingEnum, hashType HashTypeEnum, ...) (ciphertext string, err error)
- func (r *Rsa) GenSerialNumber() *big.Int
- func (r *Rsa) GenerateKey(bits RsaKeySizeEnum) error
- func (r *Rsa) GetCert() *x509.Certificate
- func (r *Rsa) GetCertStr() (cert string, err error)
- func (r *Rsa) GetKeyStr(format KeyFormatEnum) (priKey, pubKey string, err error)
- func (r *Rsa) GetPrivate() *rsa.PrivateKey
- func (r *Rsa) GetPublic() *rsa.PublicKey
- func (r *Rsa) LoadCert(certPEM []byte) error
- func (r *Rsa) LoadCertByFile(certFile string) error
- func (r *Rsa) LoadCertByRaw(raw string, format FormatEnum) error
- func (r *Rsa) LoadKey(keyPem []byte) error
- func (r *Rsa) LoadKeyByFile(keyFile string) error
- func (r *Rsa) SaveCert(dir, filename string) error
- func (r *Rsa) SaveKey(format KeyFormatEnum, dir, filename string) (err error)
- func (r *Rsa) Sign(msg []byte, signType SignTypeEnum, hashType HashTypeEnum, format FormatEnum, ...) (ciphertext string, err error)
- func (r *Rsa) VerifySign(msg []byte, ciphertext string, signType SignTypeEnum, hashType HashTypeEnum, ...) (err error)
- type RsaKeySizeEnum
- type SignTypeEnum
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AbstractMode ¶
type Aes ¶
type Aes struct { Mode string Key string Iv string Nonce string Padding PaddingEnum AdditionalData string }
type CryptoPaddingEnum ¶
type CryptoPaddingEnum string
const ( PKCS1v15Padding CryptoPaddingEnum = "PKCS1v15" OAEPPadding CryptoPaddingEnum = "OAEP" )
type FormatEnum ¶
type FormatEnum string
const ( Str FormatEnum = "str" Hex FormatEnum = "hex" Base64 FormatEnum = "base64" Base64Url FormatEnum = "base64url" Base64RawUrl FormatEnum = "base64rawUrl" )
type HashTypeEnum ¶
type HashTypeEnum string
const ( Sha1 HashTypeEnum = "SHA1" Sha224 HashTypeEnum = "SHA224" Sha256 HashTypeEnum = "SHA256" Sha384 HashTypeEnum = "SHA384" Sha512 HashTypeEnum = "SHA512" )
type KeyFormatEnum ¶
type KeyFormatEnum string
const ( PKCS1 KeyFormatEnum = "PKCS1" // 格式: RSA PRIVATE KEY PKCS8 KeyFormatEnum = "PKCS8" // 格式: PRIVATE KEY )
type PaddingEnum ¶
type PaddingEnum int
const ( NoPadding PaddingEnum = 1 PKCS5 PaddingEnum = 2 PKCS7 PaddingEnum = 3 ISO10126 PaddingEnum = 4 Zero PaddingEnum = 5 ANISx923 PaddingEnum = 6 )
type PemTypeEnum ¶
type PemTypeEnum string
const ( PrivatePKCS1Pem PemTypeEnum = "RSA PRIVATE KEY" PublicPKCS1Pem PemTypeEnum = "RSA PUBLIC KEY" PrivatePKCS8Pem PemTypeEnum = "PRIVATE KEY" PublicPKCS8Pem PemTypeEnum = "PUBLIC KEY" )
func PrivatePemList ¶
func PrivatePemList() []PemTypeEnum
func PublicPemList ¶
func PublicPemList() []PemTypeEnum
type Rsa ¶
type Rsa struct {
// contains filtered or unexported fields
}
func (*Rsa) BuildCert ¶
func (r *Rsa) BuildCert(template, parentCert *x509.Certificate, parentPrivateKey *rsa.PrivateKey) error
BuildCert generates a certificate from a template and signs it with the parent's private key.
func (*Rsa) Decrypt ¶
func (r *Rsa) Decrypt(ciphertext string, padding CryptoPaddingEnum, hashType HashTypeEnum, format FormatEnum, label []byte) (plainText []byte, err error)
Decrypt decrypts the given ciphertext using RSA private key with specified padding, hash type, and format. It returns the plaintext or an error if any issue occurs during decryption.
func (*Rsa) Encrypt ¶
func (r *Rsa) Encrypt(plainText []byte, padding CryptoPaddingEnum, hashType HashTypeEnum, format FormatEnum, label []byte) (ciphertext string, err error)
Encrypt encrypts the given plaintext using RSA public key with specified padding, hash type, and format. It returns the ciphertext as a string or an error if any issue occurs during encryption.
func (*Rsa) GenSerialNumber ¶
GenSerialNumber generates a random serial number for the certificate.
func (*Rsa) GenerateKey ¶
func (r *Rsa) GenerateKey(bits RsaKeySizeEnum) error
GenerateKey generates a new RSA key pair with the specified key size.
func (*Rsa) GetCert ¶
func (r *Rsa) GetCert() *x509.Certificate
GetCert returns the X.509 certificate.
func (*Rsa) GetCertStr ¶
GetCertStr retrieves the certificate in PEM format.
func (*Rsa) GetKeyStr ¶
func (r *Rsa) GetKeyStr(format KeyFormatEnum) (priKey, pubKey string, err error)
GetKeyStr retrieves the private and public keys in PEM format.
func (*Rsa) GetPrivate ¶
func (r *Rsa) GetPrivate() *rsa.PrivateKey
GetPrivate returns the RSA private key.
func (*Rsa) LoadCertByFile ¶
LoadCertByFile loads an RSA certificate from a PEM-encoded file.
func (*Rsa) LoadCertByRaw ¶ added in v1.0.2
func (r *Rsa) LoadCertByRaw(raw string, format FormatEnum) error
LoadCertByRaw Load RSA certificate from raw data.
func (*Rsa) LoadKeyByFile ¶
LoadKeyByFile loads an RSA private/public key pair from a PEM-encoded file.
func (*Rsa) SaveKey ¶
func (r *Rsa) SaveKey(format KeyFormatEnum, dir, filename string) (err error)
SaveKey saves the private and public keys to files in PEM format.
func (*Rsa) Sign ¶
func (r *Rsa) Sign(msg []byte, signType SignTypeEnum, hashType HashTypeEnum, format FormatEnum, opts *rsa.PSSOptions) (ciphertext string, err error)
Sign signs a message using the private key, the specified signing type, hash type, and format.
func (*Rsa) VerifySign ¶
func (r *Rsa) VerifySign(msg []byte, ciphertext string, signType SignTypeEnum, hashType HashTypeEnum, format FormatEnum, opts *rsa.PSSOptions) (err error)
VerifySign verifies the signature of a message using the public key, the signature, and the specified hash type and format.
type RsaKeySizeEnum ¶
type RsaKeySizeEnum int
const ( RSA2048 RsaKeySizeEnum = 2048 RSA3072 RsaKeySizeEnum = 3072 RSA4096 RsaKeySizeEnum = 4096 )
type SignTypeEnum ¶
type SignTypeEnum string
const ( PKCS1v15 SignTypeEnum = "PKCS1v15" PSS SignTypeEnum = "PSS" )