Documentation ¶
Overview ¶
Example (FakePassword) ¶
var fakeData string var err error InitFaker(common.TestConfig.RandSeed) // default policy and length fakeData, err = Fake("password") fmt.Println(fakeData, err) // default length fakeData, _ = Fake("password", "1") fmt.Println(fakeData, err) // all specified fakeData, _ = Fake("password", "aA", 12) fmt.Println(fakeData, err)
Output: cq8d1uhfy4l4gk4p <nil> 6890465967198159 <nil> LlrvUELBmCil <nil>
Index ¶
- func AES(args ...interface{}) (ret string, err error)
- func AESCTR(args ...interface{}) (ret string, err error)
- func Abbreviate(args ...interface{}) (ret string, err error)
- func Age(args ...interface{}) (ret string, err error)
- func Base64(args ...interface{}) (ret string, err error)
- func Birthday(args ...interface{}) (ret string, err error)
- func CRC32(args ...interface{}) (ret string, err error)
- func Caesar(args ...interface{}) (ret string, err error)
- func Char2Const(args ...interface{}) (ret string, err error)
- func Const(args ...interface{}) (ret string, err error)
- func CreditCard(args ...interface{}) (ret string, err error)
- func DES(args ...interface{}) (ret string, err error)
- func DateFormat(args ...interface{}) (ret string, err error)
- func DateRound(args ...interface{}) (ret string, err error)
- func Domain(args ...interface{}) (ret string, err error)
- func ECC(args ...interface{}) (ret string, err error)
- func FF1(args ...interface{}) (ret string, err error)
- func FF3(args ...interface{}) (ret string, err error)
- func Fake(args ...interface{}) (ret string, err error)
- func GenerateEncryptCipher() error
- func HMAC(args ...interface{}) (ret string, err error)
- func IP(args ...interface{}) (ret string, err error)
- func InitFaker(seed int64) error
- func InitMangle() error
- func InitMaskCorpus(seed int64) error
- func InitShuffle(seed int64) error
- func Initialism(args ...interface{}) (ret string, err error)
- func LaplaceDPFloat64(args ...interface{}) (ret string, err error)
- func LaplaceDPInt64(args ...interface{}) (ret string, err error)
- func LicensePlate(args ...interface{}) (ret string, err error)
- func LoopMoveLeft(args ...interface{}) (ret string, err error)
- func LoopMoveRight(args ...interface{}) (ret string, err error)
- func MD5(args ...interface{}) (ret string, err error)
- func Mail(args ...interface{}) (ret string, err error)
- func Mangle(args ...interface{}) (ret string, err error)
- func Morse(args ...interface{}) (ret string, err error)
- func Number2Const(args ...interface{}) (ret string, err error)
- func NumberFloor(args ...interface{}) (ret string, err error)
- func Numeronym(args ...interface{}) (ret string, err error)
- func OrganizationCode(args ...interface{}) (ret string, err error)
- func ParseCipherConfig(file string) error
- func ParseMaskConfig(file string) (maskConfig, error)
- func Password(args ...interface{}) (ret string, err error)
- func PersonalID(args ...interface{}) (ret string, err error)
- func Phone(args ...interface{}) (ret string, err error)
- func PrintCipher()
- func RSA(args ...interface{}) (ret string, err error)
- func RegexpRandomReplace(args ...interface{}) (ret string, err error)
- func RegexpReplace(args ...interface{}) (ret string, err error)
- func Replace(args ...interface{}) (ret string, err error)
- func ReserveInner(args ...interface{}) (ret string, err error)
- func ReserveLeft(args ...interface{}) (ret string, err error)
- func ReserveMargin(args ...interface{}) (ret string, err error)
- func ReserveOuter(args ...interface{}) (ret string, err error)
- func ReserveRight(args ...interface{}) (ret string, err error)
- func Reverse(args ...interface{}) (ret string, err error)
- func Rot(args ...interface{}) (ret string, err error)
- func SHA1(args ...interface{}) (ret string, err error)
- func SHA2(args ...interface{}) (ret string, err error)
- func SM2(args ...interface{}) (ret string, err error)
- func SM3(args ...interface{}) (ret string, err error)
- func SM4(args ...interface{}) (ret string, err error)
- func Salary(args ...interface{}) (ret string, err error)
- func Shuffle(args ...interface{}) (ret string, err error)
- func ShuffleLeft(args ...interface{}) (ret string, err error)
- func ShuffleRight(args ...interface{}) (ret string, err error)
- func Smoke(args ...interface{}) (ret string, err error)
- func SmokeCharLeft(args ...interface{}) (ret string, err error)
- func SmokeCharRight(args ...interface{}) (ret string, err error)
- func SmokeInner(args ...interface{}) (ret string, err error)
- func SmokeLeft(args ...interface{}) (ret string, err error)
- func SmokeMargin(args ...interface{}) (ret string, err error)
- func SmokeOuter(args ...interface{}) (ret string, err error)
- func SmokeRight(args ...interface{}) (ret string, err error)
- func TDEA(args ...interface{}) (ret string, err error)
- func ToLower(args ...interface{}) (ret string, err error)
- func ToUpper(args ...interface{}) (ret string, err error)
- func TruncateLeft(args ...interface{}) (ret string, err error)
- func TruncateRight(args ...interface{}) (ret string, err error)
- func USCC(args ...interface{}) (ret string, err error)
- func Username(args ...interface{}) (ret string, err error)
- type EncryptCipher
- type EncryptCipherString
- type MangleConfig
- type MaskFunc
- type MaskStruct
Examples ¶
- Package (FakePassword)
- AES
- AESCTR
- Abbreviate
- Age
- Base64
- Birthday
- CRC32
- Caesar
- Char2Const
- Const
- CreditCard
- DES
- DateFormat
- DateRound
- Domain
- HMAC
- IP
- Initialism
- LicensePlate
- LoopMoveLeft
- LoopMoveRight
- MD5
- Mangle
- Morse
- Number2Const
- NumberFloor
- Numeronym
- OrganizationCode
- ParseMaskConfig
- Password
- PersonalID
- Phone
- RegexpReplace
- Replace
- ReserveInner
- ReserveLeft
- ReserveMargin
- ReserveOuter
- ReserveRight
- Reverse
- Rot
- SHA1
- SHA2
- SM3
- SM4
- Salary
- Shuffle
- Smoke
- SmokeCharLeft
- SmokeCharRight
- SmokeInner
- SmokeLeft
- SmokeMargin
- SmokeOuter
- SmokeRight
- TDEA
- ToLower
- ToUpper
- TruncateLeft
- TruncateRight
- USCC
- Username
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AES ¶
AES ...
Example ¶
fmt.Println(AES("hello world")) fmt.Println(AES("hello world", "asdfghjk12345678d18nd18n"))
Output: F5QMumnZOlCchKi2nu99rA== <nil> FfX2LiivVQbq+w9Kat0Z3w== <nil>
func AESCTR ¶
RSA ... arg1: cipherText arg2: publicKey
Example ¶
fmt.Println(AESCTR("hello world")) fmt.Println(AESCTR("hello world", "asdfghjk12345678d18nd18n"))
Output: 0URdmXIvWjcZS3U= <nil> 6JXTR6DHyv9iRRw= <nil>
func Abbreviate ¶
Abbreviate english words abbreviate https://github.com/dnnrly/abbreviate strategy-limited => stg-ltd
Example ¶
fmt.Println(Abbreviate("strategy-limited"))
Output: stg-ltd <nil>
func Age ¶
Age age default desensitize method
Example ¶
fmt.Println(Age(39)) fmt.Println(Age(23))
Output: 30 <nil> 20 <nil>
func Base64 ¶
Base64 ...
Example ¶
fmt.Println(Base64("abc")) fmt.Println(Base64(123)) fmt.Println(Base64("123"))
Output: YWJj <nil> MTIz <nil> MTIz <nil>
func Birthday ¶
Birthday birthday default desensitize method
Example ¶
fmt.Println(Birthday("20200534")) fmt.Println(Birthday("2020-05-34"))
Output: NNNNNNNN <nil> NNNN-NN-NN <nil>
func CRC32 ¶
Example ¶
fmt.Println(CRC32("abc")) fmt.Println(CRC32(123)) fmt.Println(CRC32("123"))
Output: 352441c2 <nil> 884863d2 <nil> 884863d2 <nil>
func Caesar ¶
Example ¶
for _, c := range shuffleTestCases { fmt.Println(Caesar(c, 3)) }
Output: 1234567890 <nil> 1234567890 <nil> 123def4567890 <nil> 123DEF4567890 <nil> 中文defDEF <nil> 10.199.90.105 <nil> def <nil>
func Char2Const ¶
Char2Const replace [a-zA-Z] to N args 0: value args 1: const mask string
Example ¶
fmt.Println(Char2Const("abc-def")) fmt.Println(Char2Const("ABC-DEF", "A"))
Output: NNN-NNN <nil> AAA-AAA <nil>
func Const ¶
Const replace string with const args 0: value args 1: const mask string
Example ¶
fmt.Println(Const("123", "MASKED"))
Output: MASKED <nil>
func CreditCard ¶
CreditCard credit card default desensitize method
Example ¶
fmt.Println(CreditCard("6227612145830440"))
Output: 62276121****0440 <nil>
func DES ¶
DES ...
Example ¶
fmt.Println(DES("hello world")) fmt.Println(DES("hello world", "asdfghjk"))
Output: jZLr1ir1An0IQc30XbLL3A== <nil> hf5Kqc1nUS++YuxhzQeCIw== <nil>
func DateFormat ¶
DateFormat convert date format arg1: date arg2: old date format, arg2: new date format,
Example ¶
fmt.Println(DateFormat("2021/07/23 17-26-45", "YYYY/MM/DD HH-mm-ss")) fmt.Println(DateFormat("2021-07-23 17:26:45", "YYYY-MM-DD HH:mm:ss", "YYYY/MM/DD HH-mm-ss"))
Output: 2021-07-23 17:26:45 <nil> 2021/07/23 17-26-45 <nil>
func DateRound ¶
DateRound ... arg1: date arg2: dateFormat, accuracy: accuracy second, minute, hour(default), day, month, year e.g., 2021-07-23 17:00:00、2021-01-01 00:00:00 https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html#rfc822timezone
Example ¶
fmt.Println(DateRound("2021-07-23 17:26:45", "hour")) fmt.Println(DateRound("2021-07-23 17:26:45", "second", "YYYY-MM-DD HH:mm:ss")) fmt.Println(DateRound("2021/07/23 17-26-45", "minute", "YYYY/MM/DD HH-mm-ss")) fmt.Println(DateRound("2021-07-23 17:26:45", "hour", "YYYY-MM-DD HH:mm:ss")) fmt.Println(DateRound("2021-07-23 17:26:45", "day", "YYYY-MM-DD HH:mm:ss")) fmt.Println(DateRound("2021-07-23 17:26:45", "month", "YYYY-MM-DD HH:mm:ss")) fmt.Println(DateRound("2021-07-23 17:26:45", "year", "YYYY-MM-DD HH:mm:ss")) fmt.Println(DateRound("2021@07@23 17@26@45", "xxxxx", "YYYY@MM@DD HH@mm@ss"))
Output: 2021-07-23 17:00:00 <nil> 2021-07-23 17:26:45 <nil> 2021/07/23 17-27-00 <nil> 2021-07-23 17:00:00 <nil> 2021-07-24 00:00:00 <nil> 2021-07-01 00:00:00 <nil> 2021-01-01 00:00:00 <nil> 2021@07@23 17@00@00 <nil>
func Domain ¶
Domain domain default desensitize method e.g., s*******m
Example ¶
fmt.Println(Domain("example.com"))
Output: e*********m <nil>
func FF1 ¶
FF1 format-preserving encryption, ff1 algorithm arg 0: value arg 1: radix, default 10, max size 62, min size 2. [0-9a-zA-Z] arg 2: key arg 3: tweak
func FF3 ¶
FF3 format-preserving encryption, ff3 algorithm arg 0: value arg 1: radix, default 10, max size 62, min size 2. [0-9a-zA-Z] arg 2: key arg 3: tweak
func HMAC ¶
Example ¶
fmt.Println(HMAC("helle world", "md5", "pass")) fmt.Println(HMAC("helle world", "sha1", "pass")) fmt.Println(HMAC("helle world", "sha2", "pass"))
Output: 37c4d226765f06daa3ad91a6c33a5d3e <nil> 316278d8dab3b11d98501b6f000980a1203d7e4a <nil> 3daa940668aa37073bc91dd8d71c3f42c44e8b5a91a5100a8ad7efb9c2ad6224 <nil>
func IP ¶
IP IP default desensitize method
Example ¶
fmt.Println(IP("192.168.0.1"))
Output: 127.0.0.1 <nil>
func InitMangle ¶
func InitMangle() error
func InitMaskCorpus ¶
InitMaskCorpus init mask corpus, it's cost long time
func InitShuffle ¶
func Initialism ¶
Initialism english words initialism hello world => hw
Example ¶
fmt.Println(Initialism("hello world"))
Output: hw <nil>
func LaplaceDPFloat64 ¶
LaplaceDPFloat64 differential privacy masking based on laplace arg 0: value arg 1: l0sensitivity arg 2: lInfSensitivity arg 3: epsilon arg 4: delta
func LaplaceDPInt64 ¶
LaplaceDPInt64 differential privacy masking based on laplace arg 0: value arg 1: l0sensitivity arg 2: lInfSensitivity arg 3: epsilon arg 4: delta
func LicensePlate ¶
LicensePlate licensePlate default desensitize method 京*****
Example ¶
fmt.Println(LicensePlate("鄂D71D44"))
Output: 鄂*****4 <nil>
func LoopMoveLeft ¶
LoopMoveLeft ... e.g., abcdefg left move 3 defgabc arg1: value arg2: index
Example ¶
fmt.Println(LoopMoveLeft("abcdefg", 3))
Output: defgabc <nil>
func LoopMoveRight ¶
LoopMoveRight ... e.g., abcdefg left move 3 efgabcd arg1: value arg2: index
Example ¶
fmt.Println(LoopMoveRight("abcdefg", 3))
Output: efgabcd <nil>
func MD5 ¶
Example ¶
fmt.Println(MD5("abc")) fmt.Println(MD5(123)) fmt.Println(MD5("123"))
Output: 900150983cd24fb0d6963f7d28e17f72 <nil> 202cb962ac59075b964b07152d234b70 <nil> 202cb962ac59075b964b07152d234b70 <nil>
func Mail ¶
Mail mail default desensitize method e.g., z****@***m
Example ¶
fmt.Println(Mail("zhangsan001@d18n.com"))
Output: z**********@*******m <nil>
func Mangle ¶
Mangle this func shuffle English article FPE(Format Preserve Encrypt) Chinese article should use Shuffle func, because Chinese sentences ard made by multi single character, English sentences are made by multi single words.
Example ¶
fmt.Println(Mangle("hello world!", "en_US", "secret password"))
Output: spars dream! <nil>
func Morse ¶
Example ¶
for _, c := range shuffleTestCases { fmt.Println(Morse(c)) }
Output: .---- ..--- ...-- ....- ..... -.... --... ---.. ----. ----- <nil> .---- ..--- ...-- ....- ..... -.... --... ---.. ----. ----- <nil> .---- ..--- ...-- .- -... -.-. ....- ..... -.... --... ---.. ----. ----- <nil> .---- ..--- ...-- .- -... -.-. ....- ..... -.... --... ---.. ----. ----- <nil> # # .- -... -.-. .- -... -.-. error in input: #中##文#ABCABC .---- ----- .-.-.- .---- ----. ----. .-.-.- ----. ----- .-.-.- .---- ----- ..... <nil> .- -... -.-. <nil>
func Number2Const ¶
Number2Const replace all number to 9 args 0: value args 1: const mask string
Example ¶
fmt.Println(Number2Const("(+086)130-1234-123")) fmt.Println(Number2Const("(+086)130-1234-123", 0))
Output: (+999)999-9999-999 <nil> (+000)000-0000-000 <nil>
func NumberFloor ¶
https://help.aliyun.com/document_detail/150101.html?spm=a2c4g.11186623.6.595.243a5a787EiWOe NumberFloor... eg -12.78->-12、4856->4000 arg1: value arg2: floor num
Example ¶
fmt.Println(NumberFloor(123456.789, 3)) fmt.Println(NumberFloor(43, 1)) fmt.Println(NumberFloor(3654, 3)) fmt.Println(NumberFloor(56.789, 3))
Output: 123000 <nil> 40 <nil> 3000 <nil> 0 <nil>
func Numeronym ¶
Numeronym a number-based word. internationalization => i8n
Example ¶
fmt.Println(Numeronym("internationalization")) fmt.Println(Numeronym("data-desensitization")) fmt.Println(Numeronym("hello world"))
Output: i18n <nil> d18n <nil> h3o w3d <nil>
func OrganizationCode ¶
OrganizationCode organizationCode default desensitize method
Example ¶
fmt.Println(OrganizationCode("100000439"))
Output: 100***439 <nil>
func ParseCipherConfig ¶
func ParseMaskConfig ¶
Example ¶
file := common.TestPath + "/test/mask.csv" mc, err := ParseMaskConfig(file) fmt.Println(mc, err)
Output: map[id:{shuffle []} last_name:{smokeleft [3 x]}] <nil>
func Password ¶
Password password default desensitize method
Example ¶
fmt.Println(Password("asfa@12323ssda")) fmt.Println(Password("asfa@123"))
Output: ********* <nil> ********* <nil>
func PersonalID ¶
PersonalID personal ID default desensitize method
Example ¶
fmt.Println(PersonalID("110223700003697"))
Output: 110223*****3697 <nil>
func Phone ¶
Phone phone default desensitize method e.g., 130*****123
Example ¶
fmt.Println(Phone("13000000123")) fmt.Println(Phone(13000000123))
Output: 130*****123 <nil> 130*****123 <nil>
func PrintCipher ¶
func PrintCipher()
func RegexpRandomReplace ¶
RegexpRandomReplace through regular random data relpace args 0: value args 1: regexp.Compile(expr string) args 2: max uint Maximum number of instances to generate for unbounded repeat expressions (e.g., ".*" and "{1,}") args 3: min uint Minimum number of instances to generate for unbounded repeat expressions (e.g., ".*")
func RegexpReplace ¶
RegexpReplace regexp.ReplaceAllString args 1: regexp.Compile(expr string) args 0, 2: regexp.ReplaceAllString(src, repl string)
Example ¶
fmt.Println(RegexpReplace("abcdef", "[bc]", "*"))
Output: a**def <nil>
func Replace ¶
Replace strings.Replace args 0-3: strings.Replace(s, old, new string, n int)
Example ¶
fmt.Println(Replace(123, "2", "*", -1)) fmt.Println(Replace("123", "2", "*", -1)) fmt.Println(Replace(123, "2", "x", -1)) fmt.Println(Replace(123, "2", "x", -1)) fmt.Println(Replace(12223, "2", "x", 2)) fmt.Println(Replace(123, 1, 4, -1))
Output: 1*3 <nil> 1*3 <nil> 1x3 <nil> 1x3 <nil> 1xx23 <nil> 423 <nil>
func ReserveInner ¶
ReserveInner
Example ¶
fmt.Println(ReserveInner(123456, 2, 1, "*")) fmt.Println(ReserveInner(123, 2, 1, "*")) fmt.Println(ReserveInner("123456", 2, 1, "*")) fmt.Println(ReserveInner(123456, 2, 1, "x")) fmt.Println(ReserveInner(1234, 3, 1, "x")) fmt.Println(ReserveInner(123, 1, 4, "x")) fmt.Println(ReserveInner(123, 0, 0, "x")) fmt.Println(ReserveInner(123, -1, 1, "x"))
Output: **345* <nil> *** <nil> **345* <nil> xx345x <nil> xxxx <nil> xxx <nil> 123 <nil> n should large than 0
func ReserveLeft ¶
ReserveLeft reserve left n characters args 0: value args 1: left n character args 2: strings.Repeat(src string)
Example ¶
fmt.Println(ReserveLeft(123, 2, "*")) fmt.Println(ReserveLeft("123", 2, "*")) fmt.Println(ReserveLeft(123, 2, "x")) fmt.Println(ReserveLeft(123, 3, "x")) fmt.Println(ReserveLeft(123, 4, "x")) fmt.Println(ReserveLeft(123, 0, "x")) fmt.Println(ReserveLeft(123, -1, "x")) fmt.Println(ReserveLeft("张三", 1, "某"))
Output: 12* <nil> 12* <nil> 12x <nil> 123 <nil> 123 <nil> xxx <nil> n should large than 0 张某 <nil>
func ReserveMargin ¶
ReserveMargin reserve margin n characters args 0: value args 1: margin n character args 2: strings.Repeat(src string)
Example ¶
fmt.Println(ReserveMargin(123456, 2, "*")) fmt.Println(ReserveMargin(12, 1, "*")) fmt.Println(ReserveMargin("123456", 2, "*")) fmt.Println(ReserveMargin(123456, 2, "x")) fmt.Println(ReserveMargin(1234, 3, "x")) fmt.Println(ReserveMargin(123, 4, "x")) fmt.Println(ReserveMargin(123, 0, "x")) fmt.Println(ReserveMargin(123, -1, "x")) fmt.Println(ReserveMargin("王老五", 1, "某"))
Output: 12**56 <nil> ** <nil> 12**56 <nil> 12xx56 <nil> xxxx <nil> xxx <nil> xxx <nil> n should large than 0 王某五 <nil>
func ReserveOuter ¶
ReserveOuter
Example ¶
fmt.Println(ReserveOuter(123456, 2, 1, "*")) fmt.Println(ReserveOuter(123, 2, 1, "*")) fmt.Println(ReserveOuter("123456", 2, 1, "*")) fmt.Println(ReserveOuter(123456, 2, 1, "x")) fmt.Println(ReserveOuter(1234, 3, 1, "x")) fmt.Println(ReserveOuter(123, 1, 4, "x")) fmt.Println(ReserveOuter(123, 0, 0, "x")) fmt.Println(ReserveOuter(123, -1, 1, "x"))
Output: 12***6 <nil> 123 <nil> 12***6 <nil> 12xxx6 <nil> 1234 <nil> xxx <nil> xxx <nil> n should large than 0
func ReserveRight ¶
ReserveRight reserve right n characters args 0: value args 1: right n character args 2: strings.Repeat(src string)
Example ¶
fmt.Println(ReserveRight(123, 2, "*")) fmt.Println(ReserveRight("123", 2, "*")) fmt.Println(ReserveRight(123, 2, "x")) fmt.Println(ReserveRight(123, 3, "x")) fmt.Println(ReserveRight(123, 4, "x")) fmt.Println(ReserveRight(123, 0, "x")) fmt.Println(ReserveRight(123, -1, "x"))
Output: *23 <nil> *23 <nil> x23 <nil> 123 <nil> 123 <nil> xxx <nil> n should large than 0
func Reverse ¶
Reverse string reverse
Example ¶
fmt.Println(Reverse("abc")) fmt.Println(Reverse(123)) fmt.Println(Reverse("信息隐藏实验"))
Output: cba <nil> 321 <nil> 验实藏隐息信 <nil>
func Rot ¶
Rot letter substitution with the Nth letter after it in the alphabet.
Example ¶
for _, c := range shuffleTestCases { fmt.Println(Rot(c, 5)) fmt.Println(Rot(c, 13)) fmt.Println(Rot(c, 18)) fmt.Println(Rot(c, 47)) fmt.Println(Rot(c, 32768)) fmt.Println(Rot(c, 3)) }
Output: 6789012345 <nil> 1234567890 <nil> 6789012345 <nil> `abcdefgh_ <nil> 6789012345 <nil> wrong mask function 6789012345 <nil> 1234567890 <nil> 6789012345 <nil> `abcdefgh_ <nil> 6789012345 <nil> wrong mask function 678abc9012345 <nil> 123nop4567890 <nil> 678nop9012345 <nil> `ab234cdefgh_ <nil> 678áâã9012345 <nil> wrong mask function 678ABC9012345 <nil> 123NOP4567890 <nil> 678NOP9012345 <nil> `abpqrcdefgh_ <nil> 678ÁÂÃ9012345 <nil> wrong mask function 中文abcABC <nil> 中文nopNOP <nil> 中文nopNOP <nil> 中文234pqr <nil> 亭攇áâãÁÂà <nil> wrong mask function 65.644.45.650 <nil> 10.199.90.105 <nil> 65.644.45.650 <nil> `_]`hh]h_]`_d <nil> 65®644®45®650 <nil> wrong mask function abc <nil> nop <nil> nop <nil> 234 <nil> áâã <nil> wrong mask function
func SHA1 ¶
Example ¶
fmt.Println(SHA1("abc")) fmt.Println(SHA1(123)) fmt.Println(SHA1("123"))
Output: a9993e364706816aba3e25717850c26c9cd0d89d <nil> 40bd001563085fc35165329ea1ff5c5ecbdbbeef <nil> 40bd001563085fc35165329ea1ff5c5ecbdbbeef <nil>
func SHA2 ¶
Example ¶
fmt.Println(SHA2("abc")) fmt.Println(SHA2(123)) fmt.Println(SHA2("123"))
Output: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad <nil> a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3 <nil> a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3 <nil>
func SM3 ¶
SM3 ... arg1: cipherText
Example ¶
fmt.Println(SM3("hello world"))
Output: 44f0061e69fa6fdfc290c494654a05dc0c053da7e5c52b84ef93a9d67d3fff88 <nil>
func SM4 ¶
SM4 ... arg1: cipherText
Example ¶
fmt.Println(SM4("hello world"))
Output: b9b1742de155fe5720c0b8b1b95e3134 <nil>
func Salary ¶
Salary salary default desensitize method
Example ¶
fmt.Println(Salary(1300)) fmt.Println(Salary(500))
Output: 1000 <nil> 0 <nil>
func Shuffle ¶
Shuffle shuffle and keep data type arg 0: value arg 1: corpus name
Example ¶
InitShuffle(common.TestConfig.RandSeed) for _, c := range shuffleTestCases { r, err := Shuffle(c) fmt.Println(r, err) }
Output: 7964358102 <nil> 7964358102 <nil> 796tbq4358102 <nil> 796FNW4358102 <nil> 蕉均tbqFNW <nil> 72.700.02.723 <nil> tbq <nil>
func ShuffleLeft ¶
ShuffleLeft shuffle left and keep data type 保持后n位不变,混淆其余部分。可针对字母和数字字符在同为字母或数字范围内进行混淆,特殊符号将保留。
func ShuffleRight ¶
ShuffleRight shuffle right and keep data type 保持前n位不变,混淆其余部分。可针对字母和数字字符在同为字母或数字范围内进行混淆,特殊符号将保留。
func Smoke ¶
Smoke replace every character with mask args 0: value args 1: replacement
Example ¶
fmt.Println(Smoke(123, "*")) fmt.Println(Smoke("123", "*")) fmt.Println(Smoke(123, "x"))
Output: *** <nil> *** <nil> xxx <nil>
func SmokeCharLeft ¶
SmokeCharLeft mask left before specify char e.g., ***@example.com arg0 value arg1 char like "@" 、"&"、 "." arg2 replace char like '*','#'
Example ¶
fmt.Println(SmokeCharLeft("zhangsan123@example.com", "@", "*")) fmt.Println(SmokeCharLeft("zhangsan123&example.com", "&", "*")) fmt.Println(SmokeCharLeft("zhangsan123@example.com", ".", "*")) fmt.Println(SmokeCharLeft("@example.com", "@", "*")) fmt.Println(SmokeCharLeft("example.com@", "@", "*")) fmt.Println(SmokeCharLeft("@", "@", "*")) fmt.Println(SmokeCharLeft("", "@", "*"))
Output: ***********@example.com <nil> ***********&example.com <nil> *******************.com <nil> @example.com <nil> ***********@ <nil> @ <nil> <nil>
func SmokeCharRight ¶
SmokeCharRight mask right after specify char e.g., user@**** arg0 value arg1 char like "@" 、"&"、 "." arg2 replace char like '*','#'
Example ¶
fmt.Println(SmokeCharRight("zhangsan123@example.com", "@", "*")) fmt.Println(SmokeCharRight("zhangsan123&example.com", "&", "*")) fmt.Println(SmokeCharRight("zhangsan123@example.com", ".", "*")) fmt.Println(SmokeCharRight("@example.com", "@", "*")) fmt.Println(SmokeCharRight("example.com@", "@", "*")) fmt.Println(SmokeCharLeft("@", "@", "*")) fmt.Println(SmokeCharRight("", "@", "*"))
Output: zhangsan123@*********** <nil> zhangsan123&*********** <nil> zhangsan123@example.*** <nil> @*********** <nil> example.com@ <nil> @ <nil> <nil>
func SmokeInner ¶
SmokeInner mysql mask_inner args 0: value args 1, 2: left, right int args 3: strings.Repeat(src string)
Example ¶
fmt.Println(SmokeInner(123456, 2, 1, "*")) fmt.Println(SmokeInner(123, 2, 1, "*")) fmt.Println(SmokeInner("123456", 2, 1, "*")) fmt.Println(SmokeInner(123456, 2, 1, "x")) fmt.Println(SmokeInner(1234, 3, 1, "x")) fmt.Println(SmokeInner(123, 1, 4, "x")) fmt.Println(SmokeInner(123, 0, 0, "x")) fmt.Println(SmokeInner(123, -1, 1, "x"))
Output: 12***6 <nil> 123 <nil> 12***6 <nil> 12xxx6 <nil> 1234 <nil> xxx <nil> xxx <nil> n should large than 0
func SmokeLeft ¶
SmokeLeft replace left n characters args 0: value args 1: left n character args 2: replacement
Example ¶
fmt.Println(SmokeLeft(123, 2, "*")) fmt.Println(SmokeLeft("123", 2, "•")) fmt.Println(SmokeLeft(123, 2, "x")) fmt.Println(SmokeLeft(123, 3, "x")) fmt.Println(SmokeLeft(123, 4, "x")) fmt.Println(SmokeLeft(123, 0, "x")) fmt.Println(SmokeLeft(123, -1, "x"))
Output: **3 <nil> ••3 <nil> xx3 <nil> xxx <nil> xxx <nil> 123 <nil> n should large than 0
func SmokeMargin ¶
ReserveRight smoke margin n characters args 0: value args 1: margin n character args 2: strings.Repeat(src string)
Example ¶
fmt.Println(SmokeMargin(123456, 2, "*")) fmt.Println(SmokeMargin("123456", 2, "*")) fmt.Println(SmokeMargin(123456, 2, "x")) fmt.Println(SmokeMargin(1234, 3, "x")) fmt.Println(SmokeMargin(123, 4, "x")) fmt.Println(SmokeMargin(123, 0, "x")) fmt.Println(SmokeMargin(123, -1, "x"))
Output: **34** <nil> **34** <nil> xx34xx <nil> xxxx <nil> xxx <nil> 123 <nil> n should large than 0
func SmokeOuter ¶
SmokeOuter mysql mask_outer args 0: value args 1, 2: left, right int args 3: strings.Repeat(src string)
Example ¶
fmt.Println(SmokeOuter(123456, 2, 1, "*")) fmt.Println(SmokeOuter(123, 2, 1, "*")) fmt.Println(SmokeOuter("123456", 2, 1, "*")) fmt.Println(SmokeOuter(123456, 2, 1, "x")) fmt.Println(SmokeOuter(1234, 3, 1, "x")) fmt.Println(SmokeOuter(123, 1, 4, "x")) fmt.Println(SmokeOuter(123, 0, 0, "x")) fmt.Println(SmokeOuter(123, -1, 1, "x"))
Output: **345* <nil> *** <nil> **345* <nil> xx345x <nil> xxxx <nil> xxx <nil> 123 <nil> n should large than 0
func SmokeRight ¶
SmokeRight smoke right n characters args 0: value args 1: right n character args 2: strings.Repeat(src string)
Example ¶
fmt.Println(SmokeRight(123, 2, "*")) fmt.Println(SmokeRight("123", 2, "*")) fmt.Println(SmokeRight(123, 2, "x")) fmt.Println(SmokeRight(123, 3, "x")) fmt.Println(SmokeRight(123, 4, "x")) fmt.Println(SmokeRight(123, 0, "x")) fmt.Println(SmokeRight(123, -1, "x"))
Output: 1** <nil> 1** <nil> 1xx <nil> xxx <nil> xxx <nil> 123 <nil> n should large than 0
func TDEA ¶
TDEA ...
Example ¶
fmt.Println(TDEA("hello world")) fmt.Println(TDEA("hello world", "asdfghjk12345678d18nd18n"))
Output: F0HMxhk+uKKBSlR1IAyt+Q== <nil> lrorDbcC2s92Pn6TYeOl5A== <nil>
func ToLower ¶
ToLower strings.ToLower
Example ¶
fmt.Println(ToLower("aBc")) fmt.Println(ToUpper(123)) fmt.Println(ToUpper("123"))
Output: abc <nil> 123 <nil> 123 <nil>
func ToUpper ¶
ToUpper strings.ToUpper
Example ¶
fmt.Println(ToUpper("aBc")) fmt.Println(ToUpper(123)) fmt.Println(ToUpper("123"))
Output: ABC <nil> 123 <nil> 123 <nil>
func TruncateLeft ¶
TruncateLeft truncate left n characters arg 0: value arg 1: index
Example ¶
fmt.Println(TruncateLeft("abcdef", 2)) fmt.Println(TruncateLeft("abcdef", 20)) fmt.Println(TruncateLeft("中文abc", 4))
Output: ef <nil> abcdef <nil> 文abc <nil>
func TruncateRight ¶
Example ¶
fmt.Println(TruncateRight("abcdef", 2)) fmt.Println(TruncateRight("abcdef", 20)) fmt.Println(TruncateRight("中文abc", 2))
Output: ab <nil> abcdef <nil> 中文 <nil>
Types ¶
type EncryptCipher ¶
type EncryptCipher struct { FFKey []byte FFTweak []byte PublicKeyRSA []byte PrivateKeyRSA []byte PublicKeyECC []byte PrivateKeyECC []byte PrivateKeySM2 *sm2.PrivateKey SM3Hash hash.Hash SM4Key []byte SM4IV []byte AESKey []byte AESIV []byte DESKey []byte DESIV []byte TDEAKey []byte TDEAIV []byte AESCTRKey []byte AESCTRIV []byte }
type EncryptCipherString ¶
type EncryptCipherString struct { FFKey string `yaml:"FFKey"` FFTweak string `yaml:"FFTweak"` PublicKeyRSA string `yaml:"PublicKeyRSA"` PrivateKeyRSA string `yaml:"PrivateKeyRSA"` PublicKeyECC string `yaml:"PublicKeyECC"` PrivateKeyECC string `yaml:"PrivateKeyECC"` PrivateKeySM2 string `yaml:"PrivateKeySM2"` SM4Key string `yaml:"SM4Key"` SM4IV string `yaml:"SM4IV"` AESKey string `yaml:"AESKey"` AESIV string `yaml:"AESIV"` DESKey string `yaml:"DESKey"` DESIV string `yaml:"DESIV"` TDEAKey string `yaml:"TDEAKey"` TDEAIV string `yaml:"TDEAIV"` AESCTRKey string `yaml:"AESCTRKey"` AESCTRIV string `yaml:"AESCTRIV"` }
type MangleConfig ¶
type MangleConfig struct { // Corpus of words to use as replacements. An array of word lengths, each // containing an array of words of that length. Corpus mangleCorpus // A sufficiently long secret, used as a salt so rainbow tables cannot be // used to reverse the hashes. Secret string }
MangleConfig is used to configure an instance prior to mangling.
type MaskStruct ¶
type MaskStruct struct {
Config maskConfig // mask config
}
func NewMaskStruct ¶
func NewMaskStruct(file string) (*MaskStruct, error)
func (*MaskStruct) Mask ¶
func (m *MaskStruct) Mask(name string, value interface{}) (ret string, err error)
Mask mask column data for SQL query name: column name, case insensitive value: column value
func (*MaskStruct) MaskRow ¶
func (m *MaskStruct) MaskRow(header []common.HeaderColumn, row []string) (ret []string, err error)
MaskRow mask data for read file