mask

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: Apache-2.0 Imports: 49 Imported by: 1

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AES

func AES(args ...interface{}) (ret string, err error)

AES ...

Example
fmt.Println(AES("hello world"))
fmt.Println(AES("hello world", "asdfghjk12345678d18nd18n"))
Output:

F5QMumnZOlCchKi2nu99rA== <nil>
FfX2LiivVQbq+w9Kat0Z3w== <nil>

func AESCTR

func AESCTR(args ...interface{}) (ret string, err error)

RSA ... arg1: cipherText arg2: publicKey

Example
fmt.Println(AESCTR("hello world"))
fmt.Println(AESCTR("hello world", "asdfghjk12345678d18nd18n"))
Output:

0URdmXIvWjcZS3U= <nil>
6JXTR6DHyv9iRRw= <nil>

func Abbreviate

func Abbreviate(args ...interface{}) (ret string, err error)

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

func Age(args ...interface{}) (ret string, err error)

Age age default desensitize method

Example
fmt.Println(Age(39))
fmt.Println(Age(23))
Output:

30 <nil>
20 <nil>

func Base64

func Base64(args ...interface{}) (ret string, err error)

Base64 ...

Example
fmt.Println(Base64("abc"))
fmt.Println(Base64(123))
fmt.Println(Base64("123"))
Output:

YWJj <nil>
MTIz <nil>
MTIz <nil>

func Birthday

func Birthday(args ...interface{}) (ret string, err error)

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

func CRC32(args ...interface{}) (ret string, err error)
Example
fmt.Println(CRC32("abc"))
fmt.Println(CRC32(123))
fmt.Println(CRC32("123"))
Output:

352441c2 <nil>
884863d2 <nil>
884863d2 <nil>

func Caesar

func Caesar(args ...interface{}) (ret string, err error)
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

func Char2Const(args ...interface{}) (ret string, err error)

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

func Const(args ...interface{}) (ret string, err error)

Const replace string with const args 0: value args 1: const mask string

Example
fmt.Println(Const("123", "MASKED"))
Output:

MASKED <nil>

func CreditCard

func CreditCard(args ...interface{}) (ret string, err error)

CreditCard credit card default desensitize method

Example
fmt.Println(CreditCard("6227612145830440"))
Output:

62276121****0440 <nil>

func DES

func DES(args ...interface{}) (ret string, err error)

DES ...

Example
fmt.Println(DES("hello world"))
fmt.Println(DES("hello world", "asdfghjk"))
Output:

jZLr1ir1An0IQc30XbLL3A== <nil>
hf5Kqc1nUS++YuxhzQeCIw== <nil>

func DateFormat

func DateFormat(args ...interface{}) (ret string, err error)

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

func DateRound(args ...interface{}) (ret string, err error)

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

func Domain(args ...interface{}) (ret string, err error)

Domain domain default desensitize method e.g., s*******m

Example
fmt.Println(Domain("example.com"))
Output:

e*********m <nil>

func ECC

func ECC(args ...interface{}) (ret string, err error)

ECC ... arg1: cipherText

func FF1

func FF1(args ...interface{}) (ret string, err error)

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

func FF3(args ...interface{}) (ret string, err error)

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 Fake

func Fake(args ...interface{}) (ret string, err error)

Fake generate different type of fake data

func GenerateEncryptCipher

func GenerateEncryptCipher() error

GenerateEncryptCipher ...

func HMAC

func HMAC(args ...interface{}) (ret string, err error)
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

func IP(args ...interface{}) (ret string, err error)

IP IP default desensitize method

Example
fmt.Println(IP("192.168.0.1"))
Output:

127.0.0.1 <nil>

func InitFaker

func InitFaker(seed int64) error

func InitMangle

func InitMangle() error

func InitMaskCorpus

func InitMaskCorpus(seed int64) error

InitMaskCorpus init mask corpus, it's cost long time

func InitShuffle

func InitShuffle(seed int64) error

func Initialism

func Initialism(args ...interface{}) (ret string, err error)

Initialism english words initialism hello world => hw

Example
fmt.Println(Initialism("hello world"))
Output:

hw <nil>

func LaplaceDPFloat64

func LaplaceDPFloat64(args ...interface{}) (ret string, err error)

LaplaceDPFloat64 differential privacy masking based on laplace arg 0: value arg 1: l0sensitivity arg 2: lInfSensitivity arg 3: epsilon arg 4: delta

func LaplaceDPInt64

func LaplaceDPInt64(args ...interface{}) (ret string, err error)

LaplaceDPInt64 differential privacy masking based on laplace arg 0: value arg 1: l0sensitivity arg 2: lInfSensitivity arg 3: epsilon arg 4: delta

func LicensePlate

func LicensePlate(args ...interface{}) (ret string, err error)

LicensePlate licensePlate default desensitize method 京*****

Example
fmt.Println(LicensePlate("鄂D71D44"))
Output:

鄂*****4 <nil>

func LoopMoveLeft

func LoopMoveLeft(args ...interface{}) (ret string, err error)

LoopMoveLeft ... e.g., abcdefg left move 3 defgabc arg1: value arg2: index

Example
fmt.Println(LoopMoveLeft("abcdefg", 3))
Output:

defgabc <nil>

func LoopMoveRight

func LoopMoveRight(args ...interface{}) (ret string, err error)

LoopMoveRight ... e.g., abcdefg left move 3 efgabcd arg1: value arg2: index

Example
fmt.Println(LoopMoveRight("abcdefg", 3))
Output:

efgabcd <nil>

func MD5

func MD5(args ...interface{}) (ret string, err error)
Example
fmt.Println(MD5("abc"))
fmt.Println(MD5(123))
fmt.Println(MD5("123"))
Output:

900150983cd24fb0d6963f7d28e17f72 <nil>
202cb962ac59075b964b07152d234b70 <nil>
202cb962ac59075b964b07152d234b70 <nil>

func Mail

func Mail(args ...interface{}) (ret string, err error)

Mail mail default desensitize method e.g., z****@***m

Example
fmt.Println(Mail("zhangsan001@d18n.com"))
Output:

z**********@*******m <nil>

func Mangle

func Mangle(args ...interface{}) (ret string, err error)

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

func Morse(args ...interface{}) (ret string, err error)
Example
for _, c := range shuffleTestCases {
	fmt.Println(Morse(c))
}
Output:

.---- ..--- ...-- ....- ..... -.... --... ---.. ----. ----- <nil>
.---- ..--- ...-- ....- ..... -.... --... ---.. ----. ----- <nil>
.---- ..--- ...-- .- -... -.-. ....- ..... -.... --... ---.. ----. ----- <nil>
.---- ..--- ...-- .- -... -.-. ....- ..... -.... --... ---.. ----. ----- <nil>
# # .- -... -.-. .- -... -.-. error in input: #中##文#ABCABC
.---- ----- .-.-.- .---- ----. ----. .-.-.- ----. ----- .-.-.- .---- ----- ..... <nil>
.- -... -.-. <nil>

func Number2Const

func Number2Const(args ...interface{}) (ret string, err error)

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

func NumberFloor(args ...interface{}) (ret string, err error)

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

func Numeronym(args ...interface{}) (ret string, err error)

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

func OrganizationCode(args ...interface{}) (ret string, err error)

OrganizationCode organizationCode default desensitize method

Example
fmt.Println(OrganizationCode("100000439"))
Output:

100***439 <nil>

func ParseCipherConfig

func ParseCipherConfig(file string) error

func ParseMaskConfig

func ParseMaskConfig(file string) (maskConfig, error)
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

func Password(args ...interface{}) (ret string, err error)

Password password default desensitize method

Example
fmt.Println(Password("asfa@12323ssda"))
fmt.Println(Password("asfa@123"))
Output:

********* <nil>
********* <nil>

func PersonalID

func PersonalID(args ...interface{}) (ret string, err error)

PersonalID personal ID default desensitize method

Example
fmt.Println(PersonalID("110223700003697"))
Output:

110223*****3697 <nil>

func Phone

func Phone(args ...interface{}) (ret string, err error)

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 RSA

func RSA(args ...interface{}) (ret string, err error)

RSA ... arg1: cipherText

func RegexpRandomReplace

func RegexpRandomReplace(args ...interface{}) (ret string, err error)

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

func RegexpReplace(args ...interface{}) (ret string, err error)

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

func Replace(args ...interface{}) (ret string, err error)

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

func ReserveInner(args ...interface{}) (ret string, err error)

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

func ReserveLeft(args ...interface{}) (ret string, err error)

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

func ReserveMargin(args ...interface{}) (ret string, err error)

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

func ReserveOuter(args ...interface{}) (ret string, err error)

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

func ReserveRight(args ...interface{}) (ret string, err error)

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

func Reverse(args ...interface{}) (ret string, err error)

Reverse string reverse

Example
fmt.Println(Reverse("abc"))
fmt.Println(Reverse(123))
fmt.Println(Reverse("信息隐藏实验"))
Output:

cba <nil>
321 <nil>
验实藏隐息信 <nil>

func Rot

func Rot(args ...interface{}) (ret string, err error)

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

func SHA1(args ...interface{}) (ret string, err error)
Example
fmt.Println(SHA1("abc"))
fmt.Println(SHA1(123))
fmt.Println(SHA1("123"))
Output:

a9993e364706816aba3e25717850c26c9cd0d89d <nil>
40bd001563085fc35165329ea1ff5c5ecbdbbeef <nil>
40bd001563085fc35165329ea1ff5c5ecbdbbeef <nil>

func SHA2

func SHA2(args ...interface{}) (ret string, err error)
Example
fmt.Println(SHA2("abc"))
fmt.Println(SHA2(123))
fmt.Println(SHA2("123"))
Output:

ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad <nil>
a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3 <nil>
a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3 <nil>

func SM2

func SM2(args ...interface{}) (ret string, err error)

SM2 ... arg1: cipherText

func SM3

func SM3(args ...interface{}) (ret string, err error)

SM3 ... arg1: cipherText

Example
fmt.Println(SM3("hello world"))
Output:

44f0061e69fa6fdfc290c494654a05dc0c053da7e5c52b84ef93a9d67d3fff88 <nil>

func SM4

func SM4(args ...interface{}) (ret string, err error)

SM4 ... arg1: cipherText

Example
fmt.Println(SM4("hello world"))
Output:

b9b1742de155fe5720c0b8b1b95e3134 <nil>

func Salary

func Salary(args ...interface{}) (ret string, err error)

Salary salary default desensitize method

Example
fmt.Println(Salary(1300))
fmt.Println(Salary(500))
Output:

1000 <nil>
0 <nil>

func Shuffle

func Shuffle(args ...interface{}) (ret string, err error)

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

func ShuffleLeft(args ...interface{}) (ret string, err error)

ShuffleLeft shuffle left and keep data type 保持后n位不变,混淆其余部分。可针对字母和数字字符在同为字母或数字范围内进行混淆,特殊符号将保留。

func ShuffleRight

func ShuffleRight(args ...interface{}) (ret string, err error)

ShuffleRight shuffle right and keep data type 保持前n位不变,混淆其余部分。可针对字母和数字字符在同为字母或数字范围内进行混淆,特殊符号将保留。

func Smoke

func Smoke(args ...interface{}) (ret string, err error)

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

func SmokeCharLeft(args ...interface{}) (ret string, err error)

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

func SmokeCharRight(args ...interface{}) (ret string, err error)

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

func SmokeInner(args ...interface{}) (ret string, err error)

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

func SmokeLeft(args ...interface{}) (ret string, err error)

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

func SmokeMargin(args ...interface{}) (ret string, err error)

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

func SmokeOuter(args ...interface{}) (ret string, err error)

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

func SmokeRight(args ...interface{}) (ret string, err error)

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

func TDEA(args ...interface{}) (ret string, err error)

TDEA ...

Example
fmt.Println(TDEA("hello world"))
fmt.Println(TDEA("hello world", "asdfghjk12345678d18nd18n"))
Output:

F0HMxhk+uKKBSlR1IAyt+Q== <nil>
lrorDbcC2s92Pn6TYeOl5A== <nil>

func ToLower

func ToLower(args ...interface{}) (ret string, err error)

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

func ToUpper(args ...interface{}) (ret string, err error)

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

func TruncateLeft(args ...interface{}) (ret string, err error)

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

func TruncateRight(args ...interface{}) (ret string, err error)
Example
fmt.Println(TruncateRight("abcdef", 2))
fmt.Println(TruncateRight("abcdef", 20))
fmt.Println(TruncateRight("中文abc", 2))
Output:

ab <nil>
abcdef <nil>
中文 <nil>

func USCC

func USCC(args ...interface{}) (ret string, err error)

USCC uscc default desensitize method

Example
fmt.Println(USCC("71797173LM37QP0D4H"))
Output:

717971********0D4H <nil>

func Username

func Username(args ...interface{}) (ret string, err error)

Username username default desensitize method e.g., 王**

Example
fmt.Println(Username("张三"))
fmt.Println(Username("王二狗"))
fmt.Println(Username("Dave Li"))
Output:

张* <nil>
王** <nil>
D****** <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 MaskFunc

type MaskFunc func(args ...interface{}) (ret string, err error)

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

Jump to

Keyboard shortcuts

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