119 lines
3.2 KiB
Go
119 lines
3.2 KiB
Go
// +build linux
|
||
|
||
package utils
|
||
|
||
/*
|
||
#cgo CFLAGS: -I.
|
||
|
||
#cgo LDFLAGS: -L./lib/linux -lsdkcore
|
||
|
||
#include "sdkcore.h"
|
||
#include <stdlib.h>
|
||
*/
|
||
import "C"
|
||
|
||
import (
|
||
"fmt"
|
||
"unsafe"
|
||
|
||
"finclip-app-manager/infrastructure/config"
|
||
)
|
||
|
||
const (
|
||
BundleIDFinChatIOS = "com.finogeeks.finchat.oa"
|
||
BundleIDFinChatAndroid = "com.finogeeks.finochatapp"
|
||
BundleFTHelp = "com.finogeeks.mop.finosprite"
|
||
BundleIDFinElves = "com.finogeeks.finosprite"
|
||
BundleIDDemo = "com.finogeeks.finchat.finappletdemo"
|
||
BundleIDSample = "com.finogeeks.lib.applet.sample"
|
||
BundleIdVerifyAssistant = "com.finogeeks.mop.finoverify"
|
||
|
||
SecretFinChatIOS = "919248e19a6c7fd3"
|
||
SecretFinChatAndroid = "154a4a31a57e75cb"
|
||
SecretFinElves = "703b9026be3d6bc5"
|
||
SecretDemo = "705b46f78820c7a8"
|
||
SecretSample = "42ac8b95d32b95e7"
|
||
SecretVerifyAssistant = "b2f3d5bd38b0bfa5"
|
||
)
|
||
|
||
const (
|
||
BUFF_LEN = 1024 * 4
|
||
)
|
||
|
||
var SDKKeyFinChatIOS string
|
||
var SDKKeyFinChatAndroid string
|
||
var SDKKeyFTHelp string
|
||
var SDKKeyFinElves string
|
||
var SDKKeyDemo string
|
||
var SDKKeySample string
|
||
var SDKKeyVerifyAssistant string
|
||
var SDKArry []string
|
||
|
||
func init() {
|
||
ver := config.Cfg.SDKVersion
|
||
SDKKeyFinChatIOS = Encrypt(ver + "&" + BundleIDFinChatIOS)
|
||
SDKKeyFinChatAndroid = Encrypt(ver + "&" + BundleIDFinChatAndroid)
|
||
SDKKeyFTHelp = Encrypt(ver + "&" + BundleFTHelp)
|
||
SDKKeyFinElves = Encrypt(ver + "&" + BundleIDFinElves)
|
||
SDKKeyDemo = Encrypt(ver + "&" + BundleIDDemo)
|
||
SDKKeySample = Encrypt(ver + "&" + BundleIDSample)
|
||
SDKKeyVerifyAssistant = Encrypt(ver + "&" + BundleIdVerifyAssistant)
|
||
SDKArry = []string{SDKKeyFinChatIOS, SDKKeyFinChatAndroid, SDKKeyFTHelp, SDKKeyFinElves, SDKKeyDemo, SDKKeySample, SDKKeyVerifyAssistant}
|
||
fmt.Println("SDK Keys:", SDKKeyFinChatIOS, SDKKeyFTHelp, SDKKeyFinChatAndroid, SDKKeyFinElves, SDKKeyDemo, SDKKeySample, SDKKeyVerifyAssistant)
|
||
//fmt.Println("test secret:", GenAppSecret(SDKKeyFTHelp))
|
||
fmt.Println("SDK Arry", SDKArry)
|
||
}
|
||
|
||
// 国密算法加密
|
||
func EncryptSM4(str string) string {
|
||
//cmd := C.CBytes([]byte(str))
|
||
cmd := C.CString(str)
|
||
rlen := C.uint(BUFF_LEN)
|
||
s := make([]byte, BUFF_LEN)
|
||
C.encodeBySM4((*C.uchar)((unsafe.Pointer)(cmd)), C.uint(len(str)), (*C.uchar)(unsafe.Pointer(&s[0])), &rlen)
|
||
for i := 0; i < len(s); i++ {
|
||
if s[i] == 0 {
|
||
s = s[:i]
|
||
break
|
||
}
|
||
}
|
||
str2 := string(s[:])
|
||
C.free((unsafe.Pointer)(cmd))
|
||
return str2
|
||
}
|
||
|
||
// Encrypt 对称加密:调用cgo静态库
|
||
func Encrypt(str string) string {
|
||
//cmd := C.CBytes([]byte(str))
|
||
cmd := C.CString(str)
|
||
rlen := C.uint(BUFF_LEN)
|
||
s := make([]byte, BUFF_LEN)
|
||
C.encode((*C.uchar)((unsafe.Pointer)(cmd)), C.uint(len(str)), (*C.uchar)(unsafe.Pointer(&s[0])), &rlen)
|
||
for i := 0; i < len(s); i++ {
|
||
if s[i] == 0 {
|
||
s = s[:i]
|
||
break
|
||
}
|
||
}
|
||
str2 := string(s[:])
|
||
C.free((unsafe.Pointer)(cmd))
|
||
return str2
|
||
}
|
||
|
||
// Encrypt 对称加密:调用cgo静态库
|
||
func EncodeAESContent(str string) string {
|
||
cmd := C.CString(str)
|
||
rlen := C.uint(BUFF_LEN)
|
||
s := make([]byte, BUFF_LEN)
|
||
C.encodeAESContent((*C.uchar)((unsafe.Pointer)(cmd)), C.uint(len(str)), (*C.uchar)(unsafe.Pointer(&s[0])), &rlen)
|
||
for i := 0; i < len(s); i++ {
|
||
if s[i] == 0 {
|
||
s = s[:i]
|
||
break
|
||
}
|
||
}
|
||
str2 := string(s[:])
|
||
C.free((unsafe.Pointer)(cmd))
|
||
return str2
|
||
}
|