Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeAlgorithm(cryptoBytes []byte) int16
- func EncodeBytes(algorithm int16, rawCryptoBytes []byte) []byte
- func EncodeKeyBytes(rawKeyBytes []byte, keyType CryptoKeyType) []byte
- func GenerateAddress(pubKey *PubKey) []byte
- type AsymmetricCiphertext
- type AsymmetricEncryptionFunction
- type AsymmetricKeypair
- type AsymmetricKeypairGenerator
- type BaseCryptoBytes
- type BaseCryptoKey
- type Ciphertext
- type CryptoAlgorithm
- func DefinExt(name string, uid byte) CryptoAlgorithm
- func DefineAsymmetricEncryption(name string, uid byte) CryptoAlgorithm
- func DefineHash(name string, uid byte) CryptoAlgorithm
- func DefineRandom(name string, uid byte) CryptoAlgorithm
- func DefineSignature(name string, encryptable bool, uid byte) CryptoAlgorithm
- func DefineSymmetricEncryption(name string, uid byte) CryptoAlgorithm
- func (ca CryptoAlgorithm) ContractCode() int32
- func (ca CryptoAlgorithm) ContractName() string
- func (ca CryptoAlgorithm) Description() string
- func (ca CryptoAlgorithm) Equals(algorithm CryptoAlgorithm) bool
- func (ca CryptoAlgorithm) HasAsymmetricKey() bool
- func (ca CryptoAlgorithm) HasSymmetricKey() bool
- func (ca CryptoAlgorithm) IsAsymmetricEncryptionAlgorithm() bool
- func (ca CryptoAlgorithm) IsEncryptionAlgorithm() bool
- func (ca CryptoAlgorithm) IsExtAlgorithm() bool
- func (ca CryptoAlgorithm) IsHashAlgorithm() bool
- func (ca CryptoAlgorithm) IsRandomAlgorithm() bool
- func (ca CryptoAlgorithm) IsSignatureAlgorithm() bool
- func (ca CryptoAlgorithm) IsSymmetricEncryptionAlgorithm() bool
- func (ca CryptoAlgorithm) Match(algorithmBytes []byte, offset int) bool
- func (ca CryptoAlgorithm) ToString() string
- type CryptoBytes
- type CryptoDigest
- type CryptoFunction
- type CryptoKey
- type CryptoKeyType
- type CryptoService
- type HashDigest
- type HashFunction
- type PrivKey
- type PubKey
- type RandomFunction
- type RandomGenerator
- type SignatureDigest
- type SignatureFunction
- type SymmetricCiphertext
- type SymmetricEncryptionFunction
- type SymmetricKey
- type SymmetricKeyGenerator
Constants ¶
View Source
const (
ADDRESSVERSION_V1 = byte(0x91)
)
Variables ¶
View Source
var ( // 随机数算法标识 RANDOM_ALGORITHM = 0x1000 // 哈希数算法标识 HASH_ALGORITHM = 0x2000 // 签名算法标识 SIGNATURE_ALGORITHM = 0x4000 // 加密算法标识 ENCRYPTION_ALGORITHM = 0x8000 /** * 扩展密码算法标识; * 表示除了 * {@link #RANDOM_ALGORITHM}、{@link #HASH_ALGORITHM}、{@link #SIGNATURE_ALGORITHM}、{@link #ENCRYPTION_ALGORITHM} * 之外的其它非标准分类的密码算法,诸如加法同态算法、多方求和算法等; */ EXT_ALGORITHM = 0x0000 // 非对称密钥标识 ASYMMETRIC_KEY = 0x0100 // 对称密钥标识 SYMMETRIC_KEY = 0x0200 // 算法编码的字节长度;等同于 {@link #getCodeBytes(CryptoAlgorithm)} 返回的字节数组的长度 CODE_SIZE = 2 )
View Source
var ( // 非对称密钥的公钥 PUBLIC = CryptoKeyType{0x01} // 非对称密钥的私钥 PRIVATE = CryptoKeyType{0x02} // 对称密钥 SYMMETRIC = CryptoKeyType{0x03} )
View Source
var ALGORYTHM_CODE_SIZE = CODE_SIZE
算法标识符的长度
View Source
var (
KEY_TYPE_BYTES = 1
)
Functions ¶
func DecodeAlgorithm ¶
func EncodeBytes ¶
func EncodeKeyBytes ¶
func EncodeKeyBytes(rawKeyBytes []byte, keyType CryptoKeyType) []byte
Types ¶
type AsymmetricCiphertext ¶
type AsymmetricCiphertext struct {
BaseCryptoBytes
}
func NewAsymmetricCiphertext ¶
func NewAsymmetricCiphertext(algorithm CryptoAlgorithm, rawCryptoBytes []byte) *AsymmetricCiphertext
func ParseAsymmetricCiphertext ¶
func ParseAsymmetricCiphertext(cryptoBytes []byte) (*AsymmetricCiphertext, error)
func (AsymmetricCiphertext) GetRawCiphertext ¶
func (s AsymmetricCiphertext) GetRawCiphertext() []byte
type AsymmetricEncryptionFunction ¶
type AsymmetricEncryptionFunction interface { AsymmetricKeypairGenerator CryptoFunction /** * 加密; * * @param data * @return */ Encrypt(pubKey *PubKey, data []byte) (*AsymmetricCiphertext, error) /** * 解密; * * @param privKey * @param ciphertext * @return */ Decrypt(privKey *PrivKey, ciphertext *AsymmetricCiphertext) ([]byte, error) /** * 使用私钥恢复公钥; * * @param privKey PrivKey形式的私钥信息 * @return PubKey形式的公钥信息 */ RetrievePubKey(privKey *PrivKey) (*PubKey, error) /** * 校验私钥格式是否满足要求; * * @param privKeyBytes 包含算法标识、密钥掩码和私钥的字节数组 * @return 是否满足指定算法的私钥格式 */ SupportPrivKey(privKeyBytes []byte) bool /** * 将字节数组形式的私钥转换成PrivKey格式; * * @param privKeyBytes 包含算法标识和私钥的字节数组 * @return PrivKey形式的私钥 */ ParsePrivKey(privKeyBytes []byte) (*PrivKey, error) /** * 校验公钥格式是否满足要求; * * @param pubKeyBytes 包含算法标识、密钥掩码和公钥的字节数组 * @return 是否满足指定算法的公钥格式 */ SupportPubKey(pubKeyBytes []byte) bool /** * 将字节数组形式的密钥转换成PubKey格式; * * @param pubKeyBytes 包含算法标识和公钥的字节数组 * @return PubKey形式的公钥 */ ParsePubKey(pubKeyBytes []byte) (*PubKey, error) /** * 校验密文格式是否满足要求; * * @param ciphertextBytes 包含算法标识和密文的字节数组 * @return 是否满足指定算法的密文格式 */ SupportCiphertext(ciphertextBytes []byte) bool /** * 将字节数组形式的密文转换成AsymmetricCiphertext格式; * * @param ciphertextBytes 包含算法标识和密文的字节数组 * @return AsymmetricCiphertext形式的签名摘要 */ ParseCiphertext(ciphertextBytes []byte) (*AsymmetricCiphertext, error) }
type AsymmetricKeypair ¶
非对称秘钥
func NewAsymmetricKeypair ¶
func NewAsymmetricKeypair(pubKey *PubKey, privKey *PrivKey) (*AsymmetricKeypair, error)
type AsymmetricKeypairGenerator ¶
type AsymmetricKeypairGenerator interface { GenerateKeypair() (*AsymmetricKeypair, error) GenerateKeypairWithSeed(seed []byte) (*AsymmetricKeypair, error) }
*
- @Author: imuge
- @Date: 2020/4/28 2:16 下午
type BaseCryptoBytes ¶
func NewBaseCryptoBytes ¶
func NewBaseCryptoBytes(algorithm CryptoAlgorithm, rawCryptoBytes []byte) BaseCryptoBytes
func ParseBaseCryptoBytes ¶
func ParseBaseCryptoBytes(cryptoBytes []byte, support func(CryptoAlgorithm) bool) (*BaseCryptoBytes, error)
func (BaseCryptoBytes) GetAlgorithm ¶
func (b BaseCryptoBytes) GetAlgorithm() int16
func (BaseCryptoBytes) GetRawCryptoBytes ¶
func (b BaseCryptoBytes) GetRawCryptoBytes() (*bytes.Slice, error)
type BaseCryptoKey ¶
type BaseCryptoKey struct { BaseCryptoBytes // contains filtered or unexported fields }
func NewBaseCryptoKey ¶
func NewBaseCryptoKey(algorithm CryptoAlgorithm, rawKeyBytes []byte, keyType CryptoKeyType) BaseCryptoKey
func ParseBaseCryptoKey ¶
func ParseBaseCryptoKey(cryptoBytes []byte) (*BaseCryptoKey, error)
func (BaseCryptoKey) GetKeyType ¶
func (b BaseCryptoKey) GetKeyType() CryptoKeyType
func (BaseCryptoKey) GetRawKeyBytes ¶
func (b BaseCryptoKey) GetRawKeyBytes() ([]byte, error)
type CryptoAlgorithm ¶
type CryptoAlgorithm struct { Code int16 `primitiveType:"INT16"` Name string `primitiveType:"TEXT"` }
func DefinExt ¶
func DefinExt(name string, uid byte) CryptoAlgorithm
*
- 声明一项扩展的密码算法; *
- @param name 算法名称;
- @param uid 算法ID;需要在同类算法中保持唯一性;
- @return
func DefineAsymmetricEncryption ¶
func DefineAsymmetricEncryption(name string, uid byte) CryptoAlgorithm
*
- 声明一项非对称加密算法; *
- @param name 算法名称;
- @param uid 算法ID;需要在同类算法中保持唯一性;
- @return
func DefineHash ¶
func DefineHash(name string, uid byte) CryptoAlgorithm
*
- 声明一项哈希算法; *
- @param name 算法名称;
- @param uid 算法ID;需要在同类算法中保持唯一性;
- @return
func DefineRandom ¶
func DefineRandom(name string, uid byte) CryptoAlgorithm
*
- 声明一项随机数算法; *
- @param name 算法名称;
- @param uid 算法ID;需要在同类算法中保持唯一性;
- @return
func DefineSignature ¶
func DefineSignature(name string, encryptable bool, uid byte) CryptoAlgorithm
*
- 声明一项非对称密码算法; *
- @param name 算法名称;
- @param uid 算法ID;需要在同类算法中保持唯一性;
- @return
func DefineSymmetricEncryption ¶
func DefineSymmetricEncryption(name string, uid byte) CryptoAlgorithm
*
- 声明一项对称密码算法; *
- @param name 算法名称;
- @param uid 算法ID;需要在同类算法中保持唯一性;
- @return
func (CryptoAlgorithm) ContractCode ¶
func (ca CryptoAlgorithm) ContractCode() int32
func (CryptoAlgorithm) ContractName ¶
func (ca CryptoAlgorithm) ContractName() string
func (CryptoAlgorithm) Description ¶
func (ca CryptoAlgorithm) Description() string
func (CryptoAlgorithm) Equals ¶
func (ca CryptoAlgorithm) Equals(algorithm CryptoAlgorithm) bool
func (CryptoAlgorithm) HasAsymmetricKey ¶
func (ca CryptoAlgorithm) HasAsymmetricKey() bool
func (CryptoAlgorithm) HasSymmetricKey ¶
func (ca CryptoAlgorithm) HasSymmetricKey() bool
func (CryptoAlgorithm) IsAsymmetricEncryptionAlgorithm ¶
func (ca CryptoAlgorithm) IsAsymmetricEncryptionAlgorithm() bool
func (CryptoAlgorithm) IsEncryptionAlgorithm ¶
func (ca CryptoAlgorithm) IsEncryptionAlgorithm() bool
func (CryptoAlgorithm) IsExtAlgorithm ¶
func (ca CryptoAlgorithm) IsExtAlgorithm() bool
func (CryptoAlgorithm) IsHashAlgorithm ¶
func (ca CryptoAlgorithm) IsHashAlgorithm() bool
func (CryptoAlgorithm) IsRandomAlgorithm ¶
func (ca CryptoAlgorithm) IsRandomAlgorithm() bool
func (CryptoAlgorithm) IsSignatureAlgorithm ¶
func (ca CryptoAlgorithm) IsSignatureAlgorithm() bool
func (CryptoAlgorithm) IsSymmetricEncryptionAlgorithm ¶
func (ca CryptoAlgorithm) IsSymmetricEncryptionAlgorithm() bool
func (CryptoAlgorithm) Match ¶
func (ca CryptoAlgorithm) Match(algorithmBytes []byte, offset int) bool
func (CryptoAlgorithm) ToString ¶
func (ca CryptoAlgorithm) ToString() string
type CryptoBytes ¶
type CryptoBytes interface { bytes.BytesSerializable /** * 算法; * * @return */ GetAlgorithm() int16 }
type CryptoFunction ¶
type CryptoFunction interface {
GetAlgorithm() CryptoAlgorithm
}
*
- @Author: imuge
- @Date: 2020/4/28 2:13 下午
type CryptoKey ¶
type CryptoKey interface { CryptoBytes // 密钥的类型 GetKeyType() CryptoKeyType // 原始的密钥数据 GetRawKeyBytes() ([]byte, error) }
秘钥
type CryptoKeyType ¶
type CryptoKeyType struct {
Code byte
}
func DecodeKeyType ¶
func DecodeKeyType(cryptoBytes bytes.Slice) (CryptoKeyType, error)
func GetCryptoKeyType ¶
func GetCryptoKeyType(code byte) (CryptoKeyType, error)
type CryptoService ¶
type CryptoService interface {
GetFunctions() []CryptoFunction
}
type HashDigest ¶
type HashDigest struct {
BaseCryptoBytes
}
func NewHashDigest ¶
func NewHashDigest(algorithm CryptoAlgorithm, rawCryptoBytes []byte) *HashDigest
func ParseHashDigest ¶
func ParseHashDigest(cryptoBytes []byte) (*HashDigest, error)
func (HashDigest) GetRawDigest ¶
func (s HashDigest) GetRawDigest() []byte
type HashFunction ¶
type HashFunction interface { CryptoFunction /** * 计算指定数据的 hash; * * @param data * @return */ Hash(data []byte) *HashDigest /** * 校验 hash 摘要与指定的数据是否匹配; * * @param digest * @param data * @return */ Verify(digest *HashDigest, data []byte) bool /** * 校验字节数组形式的hash摘要的格式是否满足要求; * * @param digestBytes 包含算法标识和hash摘要的字节数组 * @return 是否满足指定算法的hash摘要格式 */ SupportHashDigest(digestBytes []byte) bool /** * 将字节数组形式的hash摘要转换成HashDigest格式; * * @param digestBytes 包含算法标识和hash摘要的字节数组 * @return HashDigest形式的hash摘要 */ ParseHashDigest(digestBytes []byte) (*HashDigest, error) }
type PrivKey ¶
type PrivKey struct {
BaseCryptoKey
}
私钥
func NewPrivKey ¶
func NewPrivKey(algorithm CryptoAlgorithm, rawKeyBytes []byte) *PrivKey
func ParsePrivKey ¶
type PubKey ¶
type PubKey struct {
BaseCryptoKey
}
公钥
func NewPubKey ¶
func NewPubKey(algorithm CryptoAlgorithm, rawKeyBytes []byte) *PubKey
func ParsePubKey ¶
func (PubKey) GetRawKeyBytes ¶ added in v1.3.3
type RandomFunction ¶
type RandomFunction interface { CryptoFunction Generate(seed int64) RandomGenerator }
type RandomGenerator ¶
type SignatureDigest ¶
type SignatureDigest struct {
BaseCryptoBytes
}
func NewSignatureDigest ¶
func NewSignatureDigest(algorithm CryptoAlgorithm, rawCryptoBytes []byte) *SignatureDigest
func ParseSignatureDigest ¶
func ParseSignatureDigest(cryptoBytes []byte) (*SignatureDigest, error)
func (SignatureDigest) GetRawDigest ¶
func (s SignatureDigest) GetRawDigest() []byte
type SignatureFunction ¶
type SignatureFunction interface { AsymmetricKeypairGenerator CryptoFunction /** * 计算指定数据的 hash; * * @param data 被签名消息 * @return SignatureDigest形式的签名摘要 */ Sign(privKey *PrivKey, data []byte) (*SignatureDigest, error) /** * 校验签名摘要和数据是否一致; * * @param digest 待验证的签名摘要 * @param data 被签名信息 * @return 是否验证通过 */ Verify(pubKey *PubKey, data []byte, digest *SignatureDigest) bool /** * 使用私钥恢复公钥; * * @param privKey PrivKey形式的私钥信息 * @return PubKey形式的公钥信息 */ RetrievePubKey(privKey *PrivKey) (*PubKey, error) /** * 校验私钥格式是否满足要求; * * @param privKeyBytes 包含算法标识、密钥掩码和私钥的字节数组 * @return 是否满足指定算法的私钥格式 */ SupportPrivKey(privKeyBytes []byte) bool /** * 将字节数组形式的私钥转换成PrivKey格式; * * @param privKeyBytes 包含算法标识、密钥掩码和私钥的字节数组 * @return PrivKey形式的私钥 */ ParsePrivKey(privKeyBytes []byte) (*PrivKey, error) /** * 校验公钥格式是否满足要求; * * @param pubKeyBytes 包含算法标识、密钥掩码和公钥的字节数组 * @return 是否满足指定算法的公钥格式 */ SupportPubKey(pubKeyBytes []byte) bool /** * 将字节数组形式的密钥转换成PubKey格式; * * @param pubKeyBytes 包含算法标识、密钥掩码和公钥的字节数组 * @return PubKey形式的公钥 */ ParsePubKey(pubKeyBytes []byte) (*PubKey, error) SupportDigest(digestBytes []byte) bool /** * 将字节数组形式的签名摘要转换成SignatureDigest格式; * * @param digestBytes 包含算法标识和签名摘要的字节数组 * @return SignatureDigest形式的签名摘要 */ ParseDigest(digestBytes []byte) (*SignatureDigest, error) // 从证书解析公钥 RetrievePubKeyFromCA(cert *ca.Certificate) (*PubKey, error) // 从私钥文件解析私钥 RetrievePrivKey(privateKey string) (*PrivKey, error) // 从私钥文件解析加密私钥 RetrieveEncrypedPrivKey(privateKey string, pwd []byte) (*PrivKey, error) }
type SymmetricCiphertext ¶
type SymmetricCiphertext struct {
BaseCryptoBytes
}
func NewSymmetricCiphertext ¶
func NewSymmetricCiphertext(algorithm CryptoAlgorithm, rawCryptoBytes []byte) *SymmetricCiphertext
func ParseSymmetricCiphertext ¶
func ParseSymmetricCiphertext(cryptoBytes []byte) (*SymmetricCiphertext, error)
func (SymmetricCiphertext) GetRawCiphertext ¶
func (s SymmetricCiphertext) GetRawCiphertext() []byte
type SymmetricEncryptionFunction ¶
type SymmetricEncryptionFunction interface { SymmetricKeyGenerator CryptoFunction /** * 加密; * * @param key 密钥; * @param data 明文; * @return */ Encrypt(key *SymmetricKey, data []byte) (*SymmetricCiphertext, error) /** * 解密; * * @param key 密钥; * @param ciphertext 密文; * @return */ Decrypt(key *SymmetricKey, ciphertext *SymmetricCiphertext) ([]byte, error) /** * 校验对称密钥格式是否满足要求; * * @param symmetricKeyBytes 包含算法标识、密钥掩码和对称密钥的字节数组 * @return 是否满足指定算法的对称密钥格式 */ SupportSymmetricKey(symmetricKeyBytes []byte) bool /** * 将字节数组形式的密钥转换成SymmetricKey格式; * * @param symmetricKeyBytes 包含算法标识、密钥掩码和对称密钥的字节数组 * @return SymmetricKey形式的对称密钥 */ ParseSymmetricKey(symmetricKeyBytes []byte) (*SymmetricKey, error) /** * 校验密文格式是否满足要求; * * @param ciphertextBytes 包含算法标识和密文的字节数组 * @return 是否满足指定算法的密文格式 */ SupportCiphertext(ciphertextBytes []byte) bool ParseCiphertext(ciphertextBytes []byte) (*SymmetricCiphertext, error) }
type SymmetricKey ¶
type SymmetricKey struct {
BaseCryptoKey
}
对称秘钥
func NewSymmetricKey ¶
func NewSymmetricKey(algorithm CryptoAlgorithm, rawKeyBytes []byte) *SymmetricKey
func ParseSymmetricKey ¶
func ParseSymmetricKey(keyBytes []byte) (*SymmetricKey, error)
func (SymmetricKey) GetRawKeyBytes ¶ added in v1.3.3
func (b SymmetricKey) GetRawKeyBytes() []byte
type SymmetricKeyGenerator ¶
type SymmetricKeyGenerator interface {
GenerateSymmetricKey() *SymmetricKey
}
*
- @Author: imuge
- @Date: 2020/4/28 2:14 下午
Source Files ¶
- address_encoding.go
- address_version.go
- asymmetric_ciphertext.go
- asymmetric_encryption_function.go
- asymmetric_keypair.go
- asymmetric_keypair_generator.go
- base_crypto_bytes.go
- base_crypto_key.go
- ciphertext.go
- crypto_algorithm.go
- crypto_bytes.go
- crypto_bytes_encoding.go
- crypto_digest.go
- crypto_function.go
- crypto_key.go
- crypto_key_type.go
- crypto_service.go
- hash_digest.go
- hash_function.go
- privkey.go
- pubkey.go
- random_function.go
- random_generator.go
- signature_digest.go
- signature_function.go
- symmetricKey_generator.go
- symmetric_ciphertext.go
- symmetric_encryption_function.go
- symmetric_key.go
Click to show internal directories.
Click to hide internal directories.