otpsdk

package module
v0.0.0-...-0457380 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

otp-sdk-go

接入otp服务go版sdk

Documentation

Overview

Package otpsdk implements PKCS#7 padding, as defined in RFC 5652. 源码: https://github.com/zenazn/pkcs7pad 标准:https://datatracker.ietf.org/doc/rfc2315/

Index

Constants

View Source
const (
	GenAccessTokenPath    = "/v1/access-token"
	VerifyAccessTokenPath = "/v1/access-token/verify"

	AddAccountSecretPath = "/v1/secret"
	GetAccountSecretPath = "/v1/secret"
	VerifyCodePath       = "/v1/secret/valid"
)

Variables

This section is empty.

Functions

func AddAccountSecret

func AddAccountSecret(account string) error

AddAccountSecret 增加账号密钥

func Conf

func Conf(serverSign, otpServerAddr, ServerKey, ServerIV string)

Conf 初始化配置 serverSign 服务标识(在otp server申请服务时填写的)

func GenAccessToken

func GenAccessToken() (string, error)

GenAccessToken 请求otp server生成 access token address otp server地址,例如:http://127.0.0.1:8066 serverSign 服务标识(在otp server申请服务时填写的) key,iv 服务密钥和IV

func GetQRCodeContent

func GetQRCodeContent(account string) (string, error)

GetQRCodeContent 获取密钥二维码内容

func Pad

func Pad(buf []byte, size int) []byte

Pad appends PKCS#7 padding to the given buffer such that the resulting slice of bytes has a length divisible by the given size. If you are using this function to pad a plaintext before encrypting it with a block cipher, the size should be equal to the block size of the cipher (e.g., aes.BlockSize).

func Unpad

func Unpad(buf []byte) ([]byte, error)

Unpad returns a subslice of the input buffer with trailing PKCS#7 padding removed. It checks the correctness of the padding bytes in constant time, and returns an error if the padding bytes are malformed.

func VerifyAccessToken

func VerifyAccessToken(token string) error

VerifyAccessToken 验证access token

func VerifyAndGenAccessToken

func VerifyAndGenAccessToken(token string) (string, error)

VerifyAndGenAccessToken 验证token,不通过生成获取新的token

func VerifyCode

func VerifyCode(account, code string) (bool, error)

VerifyCode 验证动态令牌

Types

type AccountSecretModel

type AccountSecretModel struct {
	ID         int64     `gorm:"column:id;primary_key" json:"id"`
	SecretSeed string    `gorm:"column:secret_seed_cipher" json:"secret"` // 密钥种子密文 = AES(KEY, 密钥种子)
	Account    string    `gorm:"column:account" json:"account"`           // 账号
	DataCheck  string    `gorm:"column:data_check" json:"dataCheck"`      // 数据校验 = HMACSHA256(KEY, secret_seed_cipher + account + is_enable)
	IsEnable   uint8     `gorm:"column:is_enable" json:"isEnable"`        // 是否启用,1启用,2禁用
	CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
	UpdateTime time.Time `gorm:"column:update_time" json:"updateTime"`
}

func GetAccountSecret

func GetAccountSecret(account string) (*AccountSecretModel, error)

GetAccountSecret 获取指定账号密钥

type Result

type Result[T any] struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

Jump to

Keyboard shortcuts

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