Documentation
¶
Index ¶
- Constants
- func GenerateTOTPCode(cfg *TOTPConfig, at time.Time) (string, error)
- func GenerateTOTPSecretURI(issuer string, account string) (string, error)
- func GetOnceKey(pin, encryptKey, basePath string) (string, error)
- func GetTOTPSecret(pin, encryptKey, basePath string) (string, error)
- func IsInitialized(basePath string) bool
- func KeyExists(keyType string, basePath string) bool
- func Load(pin, encryptKey, keyType string, basePath string) ([]byte, error)
- func SaveInitialKeys(pin, encryptKey, onceKey, totpURI, basePath string) error
- func SetOnceKey(pin, encryptKey, key, basePath string) error
- func SetTOTPSecret(pin, encryptKey, secret, basePath string) error
- func Store(pin, encryptKey, keyType string, data []byte, basePath string) error
- func VerifyTOTPCode(cfg *TOTPConfig, code string, at time.Time) (bool, error)
- type ECDHKeyPair
- type Encryptor
- func (e *Encryptor) Decrypt(cipherData []byte) ([]byte, error)
- func (e *Encryptor) DecryptGCM(cipherData []byte, nonce []byte) ([]byte, error)
- func (e *Encryptor) DecryptMessage(cipherBase64 string, nonceBase64 string) ([]byte, error)
- func (e *Encryptor) Encrypt(plainData []byte) ([]byte, error)
- func (e *Encryptor) EncryptGCM(plainData []byte) ([]byte, []byte, error)
- func (e *Encryptor) EncryptMessage(plainText []byte) (cipherBase64 string, nonceBase64 string, err error)
- type KeyExchange
- type TOTPConfig
Constants ¶
View Source
const EncryptedFileExt = ".enc"
Variables ¶
This section is empty.
Functions ¶
func GenerateTOTPCode ¶
func GenerateTOTPCode(cfg *TOTPConfig, at time.Time) (string, error)
GenerateTOTPCode 使用配置生成验证码
func GenerateTOTPSecretURI ¶
GenerateTOTPSecretURI 生成TOTP密钥URI
func GetOnceKey ¶
GetOnceKey 获取一次性密钥
func GetTOTPSecret ¶
GetTOTPSecret 获取TOTP密钥
func SaveInitialKeys ¶
SaveInitialKeys 保存初始化密钥
func SetTOTPSecret ¶
SetTOTPSecret 存储TOTP密钥
func VerifyTOTPCode ¶
VerifyTOTPCode 验证TOTP验证码
Types ¶
type ECDHKeyPair ¶
type ECDHKeyPair struct {
PrivateKey *ecdh.PrivateKey
PublicKey *ecdh.PublicKey
}
ECDHKeyPair 椭圆曲线 Diffie-Hellman 密钥对
func GenerateECDHKeyPair ¶
func GenerateECDHKeyPair() (*ECDHKeyPair, error)
GenerateECDHKeyPair 生成 ECDH 密钥对 (使用 P-256 曲线)
func (*ECDHKeyPair) GetPublicKeyBase64 ¶
func (kp *ECDHKeyPair) GetPublicKeyBase64() string
GetPublicKeyBase64 获取公钥的Base64编码
func (*ECDHKeyPair) GetPublicKeyBytes ¶
func (kp *ECDHKeyPair) GetPublicKeyBytes() []byte
GetPublicKeyBytes 获取公钥字节
type Encryptor ¶
type Encryptor struct {
Key []byte // 32字节(256位)密钥
}
Encryptor 封装加解密逻辑
func (*Encryptor) DecryptGCM ¶
DecryptGCM 使用AES-GCM解密数据
func (*Encryptor) DecryptMessage ¶
DecryptMessage 解密Base64编码的消息
func (*Encryptor) EncryptGCM ¶
EncryptGCM 使用AES-GCM加密数据
type KeyExchange ¶
type KeyExchange struct {
// contains filtered or unexported fields
}
KeyExchange 密钥交换器
func (*KeyExchange) ComputeSharedKey ¶
func (kx *KeyExchange) ComputeSharedKey(peerPublicKeyBase64 string) error
ComputeSharedKey 计算共享密钥
func (*KeyExchange) CreateEncryptor ¶
func (kx *KeyExchange) CreateEncryptor() (*Encryptor, error)
CreateEncryptor 创建基于共享密钥的加密器
func (*KeyExchange) GetPublicKeyBase64 ¶
func (kx *KeyExchange) GetPublicKeyBase64() string
GetPublicKeyBase64 获取本地公钥的Base64编码
func (*KeyExchange) GetSharedKey ¶
func (kx *KeyExchange) GetSharedKey() ([]byte, error)
GetSharedKey 获取共享密钥
Click to show internal directories.
Click to hide internal directories.