ucapp4go

package
v1.4.60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SymmAlgIDSM1 = iota
	SymmAlgIDSM4
	SymmAlgIDDES
	SymmAlgIDDESEDES
	SymmAlgIDAES256
)

Variables

View Source
var (
	OidPBES1  = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 5, 3}  // pbeWithMD5AndDES-CBC(PBES1)
	OidPBES2  = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 5, 13} // id-PBES2(PBES2)
	OidPBKDF2 = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 5, 12} // id-PBKDF2

	OidKEYMD5    = asn1.ObjectIdentifier{1, 2, 840, 113549, 2, 5}
	OidKEYSHA1   = asn1.ObjectIdentifier{1, 2, 840, 113549, 2, 7}
	OidKEYSHA256 = asn1.ObjectIdentifier{1, 2, 840, 113549, 2, 9}
	OidKEYSHA512 = asn1.ObjectIdentifier{1, 2, 840, 113549, 2, 11}

	OidAES128CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 2}
	OidAES256CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 1, 42}

	OidSM2Encryption = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1}
	OidRSAEncription = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1}

	DefaultUID = []byte{0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38}

	SM3Hash crypto.Hash = 0x00000401

	OidExtensionSubjectKeyId          = []int{2, 5, 29, 14}
	OidExtensionKeyUsage              = []int{2, 5, 29, 15}
	OidExtensionExtendedKeyUsage      = []int{2, 5, 29, 37}
	OidExtensionAuthorityKeyId        = []int{2, 5, 29, 35}
	OidExtensionBasicConstraints      = []int{2, 5, 29, 19}
	OidExtensionSubjectAltName        = []int{2, 5, 29, 17}
	OidExtensionCertificatePolicies   = []int{2, 5, 29, 32}
	OidExtensionNameConstraints       = []int{2, 5, 29, 30}
	OidExtensionCRLDistributionPoints = []int{2, 5, 29, 31}
	OidExtensionAuthorityInfoAccess   = []int{1, 3, 6, 1, 5, 5, 7, 1, 1}
)

Functions

func Base64Decode

func Base64Decode(strBase64 string) ([]byte, error)

func Base64Encode

func Base64Encode(pbData []byte) (string, error)

func CombineToPKCS12

func CombineToPKCS12(certBase64 string, certPrivateKey string, pin string, caCerts []*x5092.Certificate) ([]byte, error)

func CreatePKCS10Request

func CreatePKCS10Request(asymmType AsymmAlgType, keyBitLen int) (crypto.PrivateKey, *x509.P10CertificateRequest, error)

CreatePKCS10Request

func CreatePKCS10RequestString

func CreatePKCS10RequestString(asymmType AsymmAlgType, keyBitLen int) (string, string, string, error)

CreatePKCS10RequestString return 4 values present as: pub string pri string p10req string err error

func GenerateKeyPair

func GenerateKeyPair(asymmType AsymmAlgType, keyBitLen int) (crypto.PrivateKey, error)

func GetEncryptionAlgorithmBySymmType

func GetEncryptionAlgorithmBySymmType(symmType SymmType) int

func GetIssuerFromP7SignedData

func GetIssuerFromP7SignedData(pbSignData []byte) ([]string, error)

func GetP1FromP7SignedData

func GetP1FromP7SignedData(pbSignData []byte) ([][]byte, error)

func GetPlainTextFromP7SignedData

func GetPlainTextFromP7SignedData(pbSignData []byte) ([]byte, error)

func GetSeriNoFromP7SignedData

func GetSeriNoFromP7SignedData(pbSignData []byte) ([]string, error)

func HexDecode

func HexDecode(strHex string) ([]byte, error)

func HexEncode

func HexEncode(pbData []byte) (string, error)

func PKCS1SignByPriKey

func PKCS1SignByPriKey(pbPlainData []byte, userID []byte, priKey crypto.PrivateKey, hashType x509.Hash) ([]byte, error)

func PKCS1VerifyByPubKey

func PKCS1VerifyByPubKey(pbPlainData []byte, pbSignData []byte, userID []byte, pubKey crypto.PublicKey, hashType x509.Hash) error

func PrivateKeyDecrypt

func PrivateKeyDecrypt(priKey crypto.PrivateKey, pbEncData []byte) ([]byte, error)

func PublicKeyEncrypt

func PublicKeyEncrypt(pubKey crypto.PublicKey, plainData []byte) ([]byte, error)

func UrlBase64Decode

func UrlBase64Decode(strBase64 string) ([]byte, error)

func UrlBase64Encode

func UrlBase64Encode(pbData []byte) (string, error)

Types

type AsymmAlgType

type AsymmAlgType int
const (
	RSA AsymmAlgType = iota - 1
	SM2
)

type CertificateX

type CertificateX struct {
	CertificateXAttribute
}

func CertificateXConstructorWithBase64String

func CertificateXConstructorWithBase64String(strCertBase64 string, strSecretKeyBase64 string) (*CertificateX, error)

func CertificateXConstructorWithByteArray

func CertificateXConstructorWithByteArray(pbCertDER []byte, pbSecretKeyDER []byte) (*CertificateX, error)

func CertificateXConstructorWithInterface

func CertificateXConstructorWithInterface(cert *x509.Certificate, priKey crypto.PrivateKey) (*CertificateX, error)

func CertificateXConstructorWithReader

func CertificateXConstructorWithReader(readerCertBase64 io.Reader, readerSecretKeyBase64 io.Reader) (*CertificateX, error)

func GetCertFromP7SignedData

func GetCertFromP7SignedData(pbSignData []byte) ([]*CertificateX, error)

func PKCS12ParseCert

func PKCS12ParseCert(strP12Base64 string, strPin string) (*CertificateX, error)

func (*CertificateX) CreateCRL

func (certx *CertificateX) CreateCRL(rand io.Reader, revokedCerts []pkix.RevokedCertificate, now, expiry time.Time) (crlBytes []byte, err error)

func (*CertificateX) EncryptExchangeKeyWithSignCert

func (certx *CertificateX) EncryptExchangeKeyWithSignCert(encodedPlainKey []byte) (string, error)

func (*CertificateX) EnvOpen

func (certx *CertificateX) EnvOpen(pbEnvData []byte) ([]byte, error)

func (*CertificateX) EnvOpenWithOutterDecryptor

func (certx *CertificateX) EnvOpenWithOutterDecryptor(pbEnvData []byte, decryptor x509.PKCS1Decryptor) ([]byte, error)

func (*CertificateX) EnvSeal

func (certx *CertificateX) EnvSeal(pbPlainData []byte) ([]byte, error)

func (*CertificateX) GetAlgorithm

func (certx *CertificateX) GetAlgorithm() string

func (*CertificateX) GetCN

func (certx *CertificateX) GetCN() string

func (*CertificateX) GetContent

func (certx *CertificateX) GetContent() string

func (*CertificateX) GetExtension

func (certx *CertificateX) GetExtension(oid string) ([]byte, error)

func (*CertificateX) GetExtensionString

func (certx *CertificateX) GetExtensionString(oid string) (string, error)

func (*CertificateX) GetIssuer

func (certx *CertificateX) GetIssuer() string

func (*CertificateX) GetIssuerUniqueId

func (certx *CertificateX) GetIssuerUniqueId() (string, error)

func (*CertificateX) GetKeyUsage

func (certx *CertificateX) GetKeyUsage() int

func (*CertificateX) GetKeybits

func (certx *CertificateX) GetKeybits() int

func (*CertificateX) GetNotAfterSystemTime

func (certx *CertificateX) GetNotAfterSystemTime() string

func (*CertificateX) GetNotAfterTime

func (certx *CertificateX) GetNotAfterTime() time.Time

func (*CertificateX) GetNotAfterTimestamp

func (certx *CertificateX) GetNotAfterTimestamp() string

func (*CertificateX) GetNotBeforeSystemTime

func (certx *CertificateX) GetNotBeforeSystemTime() string

func (*CertificateX) GetNotBeforeTime

func (certx *CertificateX) GetNotBeforeTime() time.Time

func (*CertificateX) GetNotBeforeTimestamp

func (certx *CertificateX) GetNotBeforeTimestamp() string

func (*CertificateX) GetP7B

func (certx *CertificateX) GetP7B() ([]byte, error)

func (*CertificateX) GetPkcs1HashType

func (certx *CertificateX) GetPkcs1HashType() x509.Hash

func (*CertificateX) GetPriKeyB64

func (certx *CertificateX) GetPriKeyB64() (string, error)

func (*CertificateX) GetPubKeyB64

func (certx *CertificateX) GetPubKeyB64() (string, error)

func (*CertificateX) GetSerialNumber

func (certx *CertificateX) GetSerialNumber() string

func (*CertificateX) GetSignatureAlgorithm

func (certx *CertificateX) GetSignatureAlgorithm() string

func (*CertificateX) GetSubject

func (certx *CertificateX) GetSubject() string

func (*CertificateX) GetSubjectUniqueId

func (certx *CertificateX) GetSubjectUniqueId() (string, error)

func (*CertificateX) GetVersion

func (certx *CertificateX) GetVersion() string

func (*CertificateX) GetX509

func (certx *CertificateX) GetX509() (*x509.Certificate, error)

func (*CertificateX) PKCS1Sign

func (certx *CertificateX) PKCS1Sign(pbPlainData []byte) ([]byte, error)

func (*CertificateX) PKCS1Verify

func (certx *CertificateX) PKCS1Verify(pbPlainData []byte, pbSignData []byte) error

func (*CertificateX) PKCS7Sign

func (certx *CertificateX) PKCS7Sign(pbPlainData []byte, isDetach bool) ([]byte, error)

func (*CertificateX) PKCS7Verify

func (certx *CertificateX) PKCS7Verify(pbPlainData []byte, pbSignData []byte) error

func (*CertificateX) PrivateDecrypt

func (certx *CertificateX) PrivateDecrypt(pbEncData []byte) ([]byte, error)

func (*CertificateX) PublicEncrypt

func (certx *CertificateX) PublicEncrypt(pbPlainData []byte) ([]byte, error)

type CertificateXAttribute

type CertificateXAttribute struct {
	SecretKeyX      *SecretKeyX
	X509Cert        *x509.Certificate
	CertChain       *x509.CertPool
	CRL             []*pkix.CertificateList
	UserId          string
	EnvelopSymmType SymmType
	EmptyIV         bool
	CharSet         string
	IgnoreChain     bool
	IgnoreCRL       bool
	Pkcs1HashType   x509.Hash
	Pkcs7HashType   x509.Hash
}

type SM2EnvelopedKey

type SM2EnvelopedKey struct {
	SymmAlgID              pkix.AlgorithmIdentifier
	SymmEncryptedKey       sm2.SM2Cipher
	SM2PublicKey           asn1.BitString
	SM2EncryptedPrivateKey asn1.BitString
}

type SecretKeyX

type SecretKeyX struct {
	KeyUsage     int
	KeyAlgorithm AsymmAlgType
	Key          crypto.PrivateKey
	CharSet      string
	BuffLen      int
}

func SecretKeyXConstructorWithByteArray

func SecretKeyXConstructorWithByteArray(pbSecretKeyDER []byte) (*SecretKeyX, error)

func SecretKeyXConstructorWithInterface

func SecretKeyXConstructorWithInterface(key crypto.PrivateKey) (*SecretKeyX, error)

func (*SecretKeyX) PKCS1Sign

func (skeyx *SecretKeyX) PKCS1Sign(pbPlainData []byte, hash x5092.Hash) ([]byte, error)

func (*SecretKeyX) PrivateDecrypt

func (skeyx *SecretKeyX) PrivateDecrypt(pbEncData []byte) ([]byte, error)

type SymmAlgID

type SymmAlgID int

type SymmType

type SymmType int
const (
	AES256 SymmType = iota - 1
	SM4
	DES
	DESede
	SM1
	RC4
	AES256EmptyIV
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL