Documentation
¶
Index ¶
- Constants
- Variables
- func AESDecrypt(decodeStr string, secretKeyStr string) (string, error)
- func AESEncrypt(encodeStr string, secretKeyStr string) (string, error)
- func GenerateAndAddDurationFromNow(duration time.Duration) time.Time
- func GenerateNowDateString() string
- func GenerateRandString(length int) string
- func GetRedis() (cache.Cache, error)
- func HexToBigInt(hexStr string) (bi *big.Int, err error)
- func IsEmptyString(strArgs ...string) bool
- func MergeMaps(m1 map[string]interface{}, m2 map[string]interface{}) map[string]interface{}
- func OsFileReader(fileName string) []byte
- func ReadApiCache(ct *context.Context)
- func ReadCacheDataByKey(cacheKey string) interface{}
- func SHA1Encrypt(plainText string) ([]byte, error)
- func StringsToJSON(str string) string
- func TransformByteToJSON(str []byte) interface{}
- func TransformInterfaceToMap(origin interface{}) map[string]interface{}
- func TransformStructToJSONMap(model interface{}) (map[string]interface{}, error)
- func TransformStructToMap(st interface{}) map[string]interface{}
- func WriteApiCache(ct *context.Context, response interface{})
- type Crypto
- type ECDH
- type EllipticECDH
- func (e *EllipticECDH) ComputeSecret(privKey *EllipticPrivateKey, pubKey *EllipticPublicKey) ([]byte, error)
- func (e *EllipticECDH) DecodePEMToDERBytes(pemBytes []byte) []byte
- func (e *EllipticECDH) GenerateECKeyPair() (*EllipticPrivateKey, *EllipticPublicKey, error)
- func (e *EllipticECDH) GenerateECKeyPairToPEM(curve elliptic.Curve) ([]byte, []byte, error)
- func (e *EllipticECDH) GeneratePKIXPublicKey(publicKeyBlock string) string
- func (e *EllipticECDH) GetPKIXPublicKeyBlockFromPEM(pemBytes []byte) string
- func (e *EllipticECDH) Marshal(pub crypto.PublicKey) []byte
- func (e *EllipticECDH) ParseECPrivateKeyFromPEM(filePath string) (*EllipticECDH, error)
- func (e *EllipticECDH) ParseECPublicKeyFromPEM(publicKeyStr string) (*EllipticPublicKey, *ecdsa.PublicKey, error)
- func (e *EllipticECDH) ParsePKCS8ECPrivateKey(privateKeyDerBytes []byte) (*EllipticECDH, error)
- func (e *EllipticECDH) ParsePKIXECPublicKey(publicKeyDerBytes []byte) (*EllipticPublicKey, *ecdsa.PublicKey, error)
- func (e *EllipticECDH) Signature(messageBytes []byte, privateKey *ecdsa.PrivateKey) (string, error)
- func (e *EllipticECDH) Unmarshal(data []byte) (crypto.PublicKey, bool)
- func (e *EllipticECDH) VerifySignature(signatureData *SignatureData, publicKey *ecdsa.PublicKey) (status bool)
- type EllipticPrivateKey
- type EllipticPublicKey
- type SignatureData
Constants ¶
const ( TOP_AGENT = 8888888888 SUPERIOR_AGNET = 8888888888 LOGIN = "LOGIN" REGISTER = "REGISTER" )
const ( EC_PUBLIC_KEY_BLOCK_BEGIN = "-----BEGIN PUBLIC KEY-----" EC_PUBLIC_KEY_BLOCK_END = "-----END PUBLIC KEY-----" )
const ( // 200* REQUEST_SUCCESS uint = 200000 PARAMS_MISSING uint = 200400 TOKEN_IS_EXPIRED uint = 200401 TELEPHONE_NEED_VERIFY uint = 200203 TELEPHONE_HAS_NOT_REGISTERED uint = 200402 TELEPHONE_HAS_BEEN_USED uint = 200403 // 400* REQUEST_FAIL uint = 400000 SERVER_REJECT_REQUEST uint = 400403 // 500* SERVER_UNKNOW_ERROR uint = 500000 // business code RECORD_NOT_FOUND uint = 200404 USER_TELEPHONE_PSW_INVALID uint = 200404 ADDRESS_NOT_FOUND uint = 200404 ORDER_NOT_FOUND uint = 200404 SECURITY_CODE_INVALID uint = 200400 )
const StrSrouce string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Variables ¶
var ErrAddressNotFound = errors.New("this address was not found, please check it")
var ErrClosedPipe = errors.New("io: read/write on closed pipe")
var ErrCreateRecordsIsEmpty = errors.New("insert records is empty, please check your option")
var ErrCurrentUserIsExist = errors.New("current user is already exist, please login")
var ErrDecrypt = errors.New("sorry, your password verification failed")
var ErrEof = errors.New("EOF")
Error
var ErrInvitationCodeInvalid = errors.New("this invitation code is invalid, please check it")
var ErrMysqlInitFailure = errors.New("error, server initial [mysql] pool failure, please check it")
var ErrNoProgress = errors.New("multiple Read calls return no data or error")
var ErrOrderNotFound = "operation failure, this order was not exist or already completed"
var ErrPEMIsNotExist = errors.New("sorry, parse key fail, the PEM file is empty")
var ErrParamsInValid = errors.New("sorry, your params are invalid, please check it")
var ErrParamsMissing = errors.New("sorry, your request params missing")
var ErrPrivKeyParseFailedFromPEM = errors.New("failed to parse private key from PEM file")
var ErrProductNotFound = "sorry, this product was not found or has been removed"
var ErrPubKeyParseFailedFromPEM = errors.New("failed to parse public key from PEM file")
var ErrRecordNotFound = errors.New("this record was not found, please check it")
common
var ErrRedisInitFailure = errors.New("error, server initial [redis] pool failure, please check it")
var ErrSecurityCodeInvalid = "security code is invalid or expired, please check it or obtain another one"
var ErrSignatureInvalid = errors.New("error, request data signature is invalid")
var ErrTelOrPswInvalid = errors.New("telephone or password is invalid")
var WarnAccountNeedVerify = errors.New("your account needs to be verified by mobile phone and then set a password")
var WarnClassifiesMissing = "sorry, there are not have any classifies"
var WarnParamsMissing = errors.New("params missing in user checking")
Warning
var WarnTelephoneAlreadyRegistered = errors.New("this phone number has been registered, please login with this telephone")
var WarnTelephoneNotRegistered = errors.New("sorry, the phone number has not been registered yet, please register first")
var WarnUserTeamMissing = "sorry, your agent teams is not initial, please call the system's administrator"
Functions ¶
func AESEncrypt ¶
AES加密的具体算法为: AES-128-CBC,输出格式为 base64 AES加密时需要指定 iv:0102030405060708 AES加密时需要 padding either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256. https://github.com/darknessomi/musicbox/wiki/%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90%E6%96%B0%E7%99%BB%E5%BD%95API%E5%88%86%E6%9E%90
func GenerateNowDateString ¶
func GenerateNowDateString() string
func GenerateRandString ¶
func IsEmptyString ¶
func OsFileReader ¶
func ReadApiCache ¶
func ReadCacheDataByKey ¶
func ReadCacheDataByKey(cacheKey string) interface{}
func SHA1Encrypt ¶
func StringsToJSON ¶
func TransformByteToJSON ¶
func TransformByteToJSON(str []byte) interface{}
func TransformInterfaceToMap ¶
func TransformInterfaceToMap(origin interface{}) map[string]interface{}
func TransformStructToMap ¶
func TransformStructToMap(st interface{}) map[string]interface{}
can not handle key as Hump named
func WriteApiCache ¶
Types ¶
type Crypto ¶
type Crypto struct { SecretKey string OriginData interface{} }
func (*Crypto) CreateSecretKey ¶
type ECDH ¶
type ECDH interface { GenerateECKeyPair() (*EllipticPrivateKey, *EllipticPublicKey, error) GenerateECKeyPairToPEM(curve elliptic.Curve) ([]byte, []byte, error) GeneratePKIXPublicKey(publicKeyBlock string) string Marshal(pub crypto.PublicKey) []byte Unmarshal(data []byte) (crypto.PublicKey, bool) ParsePKCS8ECPrivateKey(privateKeyDerBytes []byte) (*EllipticECDH, error) ParseECPrivateKeyFromPEM(filePath string) (ellipticECDH *EllipticECDH, err error) ParseECPublicKeyFromPEM(publicKeyStr string) (ecPubKey *EllipticPublicKey, ecdsaPubKey *ecdsa.PublicKey, err error) ParsePKIXECPublicKey(publicKeyDerBytes []byte) (*EllipticPublicKey, *ecdsa.PublicKey, error) GetPKIXPublicKeyBlockFromPEM(pemBytes []byte) string DecodePEMToDERBytes(pemBytes []byte) []byte ComputeSecret(privKey *EllipticPrivateKey, pubKey *EllipticPublicKey) ([]byte, error) Signature(messageBytes []byte, privateKey *ecdsa.PrivateKey) (string, error) VerifySignature(signatureData *SignatureData, publicKey *ecdsa.PublicKey) (status bool) }
type EllipticECDH ¶
type EllipticECDH struct { PrivateKey *EllipticPrivateKey PublicKey *EllipticPublicKey ECDSAPrivateKey *ecdsa.PrivateKey }
func (*EllipticECDH) ComputeSecret ¶
func (e *EllipticECDH) ComputeSecret(privKey *EllipticPrivateKey, pubKey *EllipticPublicKey) ([]byte, error)
ECDH Compute Secret
func (*EllipticECDH) DecodePEMToDERBytes ¶
func (e *EllipticECDH) DecodePEMToDERBytes(pemBytes []byte) []byte
decode PEM, support private/public key, return block data
func (*EllipticECDH) GenerateECKeyPair ¶
func (e *EllipticECDH) GenerateECKeyPair() (*EllipticPrivateKey, *EllipticPublicKey, error)
generate ec key pair and return
func (*EllipticECDH) GenerateECKeyPairToPEM ¶
generate ec key pair and write them to PEM file, then return them
func (*EllipticECDH) GeneratePKIXPublicKey ¶
func (e *EllipticECDH) GeneratePKIXPublicKey(publicKeyBlock string) string
handle client public key which is less of begin and end
func (*EllipticECDH) GetPKIXPublicKeyBlockFromPEM ¶
func (e *EllipticECDH) GetPKIXPublicKeyBlockFromPEM(pemBytes []byte) string
get public key form pem and format to base64
func (*EllipticECDH) Marshal ¶
func (e *EllipticECDH) Marshal(pub crypto.PublicKey) []byte
Marshal ec public key
func (*EllipticECDH) ParseECPrivateKeyFromPEM ¶
func (e *EllipticECDH) ParseECPrivateKeyFromPEM(filePath string) (*EllipticECDH, error)
func (*EllipticECDH) ParseECPublicKeyFromPEM ¶
func (e *EllipticECDH) ParseECPublicKeyFromPEM(publicKeyStr string) (*EllipticPublicKey, *ecdsa.PublicKey, error)
func (*EllipticECDH) ParsePKCS8ECPrivateKey ¶
func (e *EllipticECDH) ParsePKCS8ECPrivateKey(privateKeyDerBytes []byte) (*EllipticECDH, error)
private pem file, parse PKCS#8 private key
func (*EllipticECDH) ParsePKIXECPublicKey ¶
func (e *EllipticECDH) ParsePKIXECPublicKey(publicKeyDerBytes []byte) (*EllipticPublicKey, *ecdsa.PublicKey, error)
func (*EllipticECDH) Signature ¶
func (e *EllipticECDH) Signature(messageBytes []byte, privateKey *ecdsa.PrivateKey) (string, error)
func (*EllipticECDH) Unmarshal ¶
func (e *EllipticECDH) Unmarshal(data []byte) (crypto.PublicKey, bool)
Unmarshal ec public key
func (*EllipticECDH) VerifySignature ¶
func (e *EllipticECDH) VerifySignature(signatureData *SignatureData, publicKey *ecdsa.PublicKey) (status bool)
type EllipticPrivateKey ¶
type EllipticPrivateKey struct {
D []byte
}
type SignatureData ¶
type SignatureData struct {
// contains filtered or unexported fields
}
SignatureData 用于保存签名的数据
func HandleSignatureData ¶
func HandleSignatureData(data string, signatureBase64 string) (signatureData *SignatureData, err error)