Documentation
¶
Index ¶
- Constants
- func ChangeAdminPin(handle unsafe.Pointer, oldPin, newPin string) error
- func ChangeUserPin(handle unsafe.Pointer, oldPin, newPin string) error
- func ClearApplicationSecurityStatus(handle unsafe.Pointer) error
- func CloseApplication(handle unsafe.Pointer) error
- func CloseContainer(cHandle unsafe.Pointer) error
- func CreateApplication(handle unsafe.Pointer, info *ApplicationInfo) (unsafe.Pointer, error)
- func CreateContainer(appHandle unsafe.Pointer, name string) (unsafe.Pointer, error)
- func CreateFile(handle unsafe.Pointer, info *FileInfo) error
- func DeleteApplication(handle unsafe.Pointer, appName string) error
- func DeleteContainer(appHandle unsafe.Pointer, cName string) error
- func DeleteFile(handle unsafe.Pointer, filename string) error
- func DeviceAuthentication(devHandle unsafe.Pointer, authenticationKey string) (err error)
- func DisConnectDevice(handle unsafe.Pointer) error
- func EnumerateApplication(handle unsafe.Pointer) ([]string, error)
- func EnumerateContainer(appHandle unsafe.Pointer) ([]string, error)
- func EnumerateDevice(present bool) ([]string, error)
- func EnumerateFile(handle unsafe.Pointer) ([]string, error)
- func ExportCertificate(cHandle unsafe.Pointer, isSign bool) ([]byte, error)
- func GetAdminPinInfo(handle unsafe.Pointer) (*internal.PINInfo, error)
- func GetDeviceState(name string) (uint, error)
- func GetUserPinInfo(handle unsafe.Pointer) (*internal.PINInfo, error)
- func ImportCertificate(cHandle unsafe.Pointer, isSign bool, cert []byte) error
- func ImportECCKeyPair(cHandle unsafe.Pointer, encKey *EnvelopedKeyBlob) error
- func ImportFileFromDevice(appName, filename, pin string) ([]byte, error)
- func LockDevice(handle unsafe.Pointer, timeout uint32) error
- func OpenApplication(handle unsafe.Pointer, appName string) (unsafe.Pointer, error)
- func OpenContainer(appHandle unsafe.Pointer, cName string) (unsafe.Pointer, error)
- func OpenDevice() (unsafe.Pointer, error)
- func OpenDeviceWithIndex(index uint, devList []string) (unsafe.Pointer, error)
- func ReadFile(handle unsafe.Pointer, filename string, offset, size uint32) ([]byte, error)
- func SetDeviceLabel(handle unsafe.Pointer, label string) error
- func UnLockDev(handle unsafe.Pointer) error
- func UnLockPIN(handle unsafe.Pointer, adminPin, newUserPin string) error
- func VerifyAdminPin(handle unsafe.Pointer, pin string) error
- func VerifyUserPin(handle unsafe.Pointer, pin string) error
- func WriteFile(handle unsafe.Pointer, filename string, offset uint32, inData []byte) error
- type ApplicationInfo
- type BlockCipherParam
- type DeviceInfo
- type ECCCipherBlob
- type ECCPrivateKeyBlob
- type ECCPublicKeyBlob
- type ECCSignatureBlob
- type EnvelopedKeyBlob
- type FileAttribute
- type FileInfo
- type PINInfo
- type RSAPrivateKeyBlob
- type RSAPublicKeyBlob
- type Version
Constants ¶
const ( MAX_RSA_MODULUS_LEN = 512 // 算法模数的最大长度 MAX_RSA_EXPONENT_LEN = 4 // 算法指数的最大长度 ECC_MAX_XCOORDINATE_LEN = 512 // ECC算法X坐标最大长度 ECC_MAX_YCOORDINATE_LEN = 512 // ECC算法Y坐标最大长度 ECC_MAX_MODULUS_BITS_LEN = 512 // ECC算法模数的最大长度 MAX_IV_LEN = 32 // 初始化向量的最大长度 )
const ( SECURE_NEVER_ACCOUNT uint32 = 0x00000000 // 不准许 SECURE_ADM_ACCOUNT uint32 = 0x00000001 // 管理员权限 SECURE_USER_ACCOUNT uint32 = 0x00000010 // 用户权限 SECURE_ANYONE_ACCOUNT uint32 = 0x000000FF // 任何人 )
const ( DEV_ABSENT_STATE = 0x00000000 // 设备不存在 DEV_PRESENT_STATE = 0x00000001 // 设备存在 DEV_UNKNOWN_STATE = 0x00000002 // 设备状态未知 )
const ( TRUE int32 = 0x00000001 // TRUE 对应 BOOL 类型 FALSE int32 = 0x00000000 // FALSE 对应 BOOL 类型 )
const ( ADMIN_TYPE = iota // 管理员PIN类型 USER_TYPE // 用户PIN类型 )
const ( EVENT_INSERT uint32 = 1 // 插入事件 EVENT_REMOVE uint32 = 2 // 拔出事件 )
const (
SM2_1 uint32 = 0x00020200
)
Variables ¶
This section is empty.
Functions ¶
func DeviceAuthentication ¶
DeviceAuthentication 生成设备认证数据并发送至设备进行设备认证 创建和删除应用之前必须要进行设备认证
devHandle 设备句柄 authenticationKey 设备预置的设备认证密钥
func EnumerateDevice ¶
EnumerateDevice 枚举所有的设备
present 为 true 表示获取当前状态为存在的设备列表,false 表示获取当前驱动支持的设备列表
func ExportCertificate ¶ added in v0.0.5
ExportCertificate 导出数字证书
cHandle 容器句柄 isSign 是否是签名证书,false表示加密证书
func GetDeviceState ¶
GetDeviceState 获取名称为 name 的设备状态,返回值 0 表示状态未知 1 表示设备存在 2 表示设备不存在
func ImportCertificate ¶ added in v0.0.5
ImportCertificate 导入数字证书
cHandle 容器句柄 isSign 是否是签名证书,false表示加密证书 cert 证书字节数字
func ImportECCKeyPair ¶ added in v0.0.6
func ImportECCKeyPair(cHandle unsafe.Pointer, encKey *EnvelopedKeyBlob) error
ImportECCKeyPair 导入加密密钥对
func ImportFileFromDevice ¶
ImportFileFromDevice 从设备中导入文件,并返回文件内容;只提供应用名、文件名、PIN码必要参数,无需关心其他操作
func OpenContainer ¶ added in v0.0.5
OpenContainer 打开名称为 cName 的容器,并返回容器句柄
appHandle 应用句柄 cName 容器名称
Types ¶
type ApplicationInfo ¶
type BlockCipherParam ¶
type BlockCipherParam struct { IV [MAX_IV_LEN]byte // 初始向量 IVLen uint32 // 初始向量实际长度 FeedBitLen uint32 // 反馈值的位长度,只针对 OFB、CFB 模式 }
BlockCipherParam 分组密码参数
type DeviceInfo ¶
type DeviceInfo struct { Version Version // 版本号 Manufacturer [64]byte // 设备厂商信息 Issuer [64]byte // 发行厂商信息 Label [32]byte // 设备标签 SerialNumber [32]byte // 序列号 HWVersion Version // 设备硬件版本 FirmwareVersion Version // 设备本身固件版本 AlgSymCap uint32 // 分组密码算法标识 AlgAsymCap uint32 // 非对称密码算法标识 AlgHashCap uint32 // 密码杂凑算法标识 DevAuthAlgId uint32 // 设备认证时使用的分组密码算法标识 TotalSpace uint32 // 设备总空间大小 MaxECCBufferSize uint32 // 能够处理的ECC加密数据大小 MaxBufferSize uint32 // 能够处理的分组运算和杂凑运算的数据大小 Reserved [64]byte // 保留扩展 }
DeviceInfo 设备信息
func GetDeviceInfo ¶
func GetDeviceInfo(handle unsafe.Pointer) (*DeviceInfo, error)
GetDeviceInfo 获取某个设备的设备信息
handle 设备句柄
type ECCCipherBlob ¶
type ECCCipherBlob struct { XCoordinate [ECC_MAX_XCOORDINATE_LEN / 8]byte YCoordinate [ECC_MAX_YCOORDINATE_LEN / 8]byte Hash [32]byte // 明文的杂凑值 CipherLen uint32 // 密文数据长度 Cipher []byte // 密文数据 }
ECCCipherBlob ECC密文数据结构
type ECCPrivateKeyBlob ¶
type ECCPrivateKeyBlob struct { BitLen uint32 // 模数的实际位长度,8的倍数 PrivateKey [ECC_MAX_MODULUS_BITS_LEN / 8]byte // 私有密钥 }
ECCPrivateKeyBlob ECC私钥数据结构
type ECCPublicKeyBlob ¶
type ECCPublicKeyBlob struct { BitLen uint32 // 模数实际位长,8的倍数 XCoordinate [ECC_MAX_XCOORDINATE_LEN / 8]byte // 曲线上点的X坐标 YCoordinate [ECC_MAX_YCOORDINATE_LEN / 8]byte // 曲线上点的Y坐标 }
ECCPublicKeyBlob ECC公钥数据结构
func GenECCKeyPair ¶ added in v0.0.6
func GenECCKeyPair(cHandle unsafe.Pointer) (*ECCPublicKeyBlob, error)
GenECCKeyPair 生成ECC签名密钥对
cHandle 容器句柄 algId 算法标识
type ECCSignatureBlob ¶
type ECCSignatureBlob struct {
// contains filtered or unexported fields
}
ECCSignatureBlob ECC签名数据结构
type EnvelopedKeyBlob ¶
type EnvelopedKeyBlob struct { Version uint32 // 版本号 PubKey ECCPublicKeyBlob // 加密密钥对的公钥 ECCCipherBlob ECCCipherBlob // 用保护公钥加密过的对称密钥密文 // contains filtered or unexported fields }
EnvelopedKeyBlob ECC加密密钥对保护结构
type FileAttribute ¶
type FileAttribute struct { FilName [32]byte // 文件名,以‘\0’结束的ASCII字符串 FileSize uint32 // 文件大小 ReadTights uint32 // 读权限 WriteRights uint32 // 写权限 }
FileAttribute 文件属性
func GetFileInfo ¶
func GetFileInfo(handle unsafe.Pointer, filename string) (*FileAttribute, error)
GetFileInfo 获取名称为 filename 的文件信息
handle 应用句柄 filename 文件名称
type RSAPrivateKeyBlob ¶
type RSAPrivateKeyBlob struct { AlgID uint32 // 算法标识号 BitLen uint32 // 模数的实际位长度,8的倍数 Modulus [MAX_RSA_MODULUS_LEN]byte // 模数,实际长度为BitLen/8字节 PublicExponent [MAX_RSA_EXPONENT_LEN]byte // 公开密钥,一般为00010001 PrivateExponent [MAX_RSA_MODULUS_LEN]byte // 私有密钥,实际长度为BitLen/8字节 Prime1 [MAX_RSA_MODULUS_LEN / 2]byte // 素数p,实际长度为BitLen/16字节 Prime2 [MAX_RSA_MODULUS_LEN / 2]byte // 素数q,实际长度为BitLen/16字节 Prime1Exponent [MAX_RSA_MODULUS_LEN / 2]byte // d mod(p-1)的值,实际长度为BitLen/16字节 Prime2Exponent [MAX_RSA_MODULUS_LEN / 2]byte // d mod(q-1)的值,实际长度为BitLen/16字节 Coefficient [MAX_RSA_MODULUS_LEN / 2]byte // q 模 p的乘法逆元,实际长度为BitLen/16字节 }
RSAPrivateKeyBlob RSA私钥数据结构
type RSAPublicKeyBlob ¶
type RSAPublicKeyBlob struct { AlgID uint32 // 算法标识号 BitLen uint32 // 模数的实际位长度,8的倍数 Modulus [MAX_RSA_MODULUS_LEN]byte // 模数,实际长度为BitLen/8字节 PublicExponent [MAX_RSA_EXPONENT_LEN]byte // 公开密钥,一般为00010001 }
RSAPublicKeyBlob RSA公钥数据结构