identity

package
v0.0.0-...-23905ef Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

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

func GenerateTOTPSecretURI(issuer string, account string) (string, error)

GenerateTOTPSecretURI 生成TOTP密钥URI

func GetOnceKey

func GetOnceKey(pin, encryptKey, basePath string) (string, error)

GetOnceKey 获取一次性密钥

func GetTOTPSecret

func GetTOTPSecret(pin, encryptKey, basePath string) (string, error)

GetTOTPSecret 获取TOTP密钥

func IsInitialized

func IsInitialized(basePath string) bool

IsInitialized 检查设备是否已经初始化

func KeyExists

func KeyExists(keyType string, basePath string) bool

KeyExists 检查密钥是否存在

func Load

func Load(pin, encryptKey, keyType string, basePath string) ([]byte, error)

Load 使用PIN+EncryptKey解密并加载数据

func SaveInitialKeys

func SaveInitialKeys(pin, encryptKey, onceKey, totpURI, basePath string) error

SaveInitialKeys 保存初始化密钥

func SetOnceKey

func SetOnceKey(pin, encryptKey, key, basePath string) error

SetOnceKey 存储一次性密钥

func SetTOTPSecret

func SetTOTPSecret(pin, encryptKey, secret, basePath string) error

SetTOTPSecret 存储TOTP密钥

func Store

func Store(pin, encryptKey, keyType string, data []byte, basePath string) error

Store 使用PIN+EncryptKey加密并存储数据

func VerifyTOTPCode

func VerifyTOTPCode(cfg *TOTPConfig, code string, at time.Time) (bool, error)

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 NewEncryptor

func NewEncryptor(key []byte) (*Encryptor, error)

NewEncryptor 创建一个新的加解密器

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(cipherData []byte) ([]byte, error)

Decrypt 解密数据

func (*Encryptor) DecryptGCM

func (e *Encryptor) DecryptGCM(cipherData []byte, nonce []byte) ([]byte, error)

DecryptGCM 使用AES-GCM解密数据

func (*Encryptor) DecryptMessage

func (e *Encryptor) DecryptMessage(cipherBase64 string, nonceBase64 string) ([]byte, error)

DecryptMessage 解密Base64编码的消息

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(plainData []byte) ([]byte, error)

Encrypt 加密数据

func (*Encryptor) EncryptGCM

func (e *Encryptor) EncryptGCM(plainData []byte) ([]byte, []byte, error)

EncryptGCM 使用AES-GCM加密数据

func (*Encryptor) EncryptMessage

func (e *Encryptor) EncryptMessage(plainText []byte) (cipherBase64 string, nonceBase64 string, err error)

EncryptMessage 加密消息并返回Base64编码的密文和nonce

type KeyExchange

type KeyExchange struct {
	// contains filtered or unexported fields
}

KeyExchange 密钥交换器

func NewKeyExchange

func NewKeyExchange() (*KeyExchange, error)

NewKeyExchange 创建新的密钥交换器

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 获取共享密钥

type TOTPConfig

type TOTPConfig struct {
	Secret    string        // TOTP密钥
	Issuer    string        // 签发者
	Account   string        // 账户名
	Period    uint          // 时间周期(秒)
	Digits    otp.Digits    // 验证码位数
	Algorithm otp.Algorithm // 哈希算法
}

TOTPConfig TOTP配置结构

func ParseTOTPURI

func ParseTOTPURI(uri string) (*TOTPConfig, error)

ParseTOTPURI 解析TOTP URI

Jump to

Keyboard shortcuts

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