github.com/sandwich-go/boost@v1.3.29/xcrypto/README.md (about) 1 # encryption 2 3 加密 4 5 - 支持 `aes` 加解密 6 - 支持 `vigenere` 加解密 7 - 支持生成 `SecretKey`、`PublicKey`、`SharedKey` 8 9 10 # 例子 11 12 ```go 13 // 生成随机私钥 14 secretKey0, err0 := curve25519.GenerateSecretKey() 15 xpanic.WhenError(err0) 16 secretKey1, err1 := curve25519.GenerateSecretKey() 17 xpanic.WhenError(err1) 18 19 // 通过私钥生成公钥 20 publicKey0, err2 := curve25519.GeneratePublicKey(secretKey0) 21 xpanic.WhenError(err2) 22 publicKey1, err3 := curve25519.GeneratePublicKey(secretKey1) 23 xpanic.WhenError(err3) 24 25 // 交换共享密钥 26 sharedKey0, err4 := curve25519.GenerateSharedKey(secretKey0, publicKey1) 27 xpanic.WhenError(err4) 28 sharedKey1, err5 := curve25519.GenerateSharedKey(secretKey1, publicKey0) 29 xpanic.WhenError(err5) 30 31 // aes 加解密 32 frame := []byte("time.Duration,[]time.Duration,map[string]*Redis此类的非基础类型的slice或者map都需要辅助指明类型") 33 encryptFrame, err6 := aes.Encrypt(frame, secretKey0) 34 xpanic.WhenError(err6) 35 decryptFrame, err7 := aes.Decrypt(encryptFrame, secretKey0) 36 xpanic.WhenError(err7) 37 xpanic.WhenTrue(string(frame) != string(decryptFrame), "encrypt/decrypt fail") 38 fmt.Println("OK") 39 ``` 40 41 Output: 42 ```text 43 OK 44 ```