init: v1.0.0

This commit is contained in:
yaole
2026-05-27 23:03:00 +08:00
commit 8d97f750eb
466 changed files with 80067 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
package fpe
import (
"errors"
"xdx.jelly/xgcl/sm/sm4"
)
// return the check code of id.
func checkCodeOfID(id0 string) byte {
panic("todo")
}
// EncryptID 加密身份证号。最后一位为校验位。
// key为SM4密钥,16字节
// tweak随机数,任意长度,可明文保存。
func EncryptID(id string, key []byte, tweak []byte) (string, error) {
if len(id) != 18 {
return "", errors.New("wrong id")
}
if len(key) != 16 {
return "", errors.New("wrong key")
}
b, err := sm4.NewCipher(key)
if err != nil {
return "", err
}
f := NewFF1(b, Numeric)
numerals, err := f.Encode(id[:len(id)-1])
if err != nil {
return "", err
}
cipher, err := f.Encrypt(tweak, numerals)
if err != nil {
return "", err
}
encryptedID, err := f.Decode(cipher)
if err != nil {
return "", err
}
// TODO: add the check code
return encryptedID, nil
}
// 加密纯数字的手机号
func EncryptPhoneNumber(phoneNumber string, key []byte, tweak []byte) (string, error) {
panic("todo")
}