@@ -28,25 +28,28 @@ func DecodeWeAppUserInfo(encryptedData string, sessionKey string, iv string) (st
28
28
}
29
29
30
30
result , resultErr := AESDecrypt (cipher , key , theIV )
31
- resultStr := string (result )
32
- fmt .Println (resultStr )
33
- return string (result ), resultErr
31
+ if resultErr != nil {
32
+ return "" , resultErr
33
+ }
34
+ return string (result ), nil
34
35
}
35
36
36
- func AESDecrypt (ciphertext , key , iv []byte ) ([]byte , error ) {
37
- block , err := aes .NewCipher (key ) //选择加密算法
38
- if err != nil {
39
- return nil , err
40
- }
41
- blockModel := cipher .NewCBCDecrypter (block , iv )
42
- plantText := make ([]byte , len (ciphertext ))
43
- blockModel .CryptBlocks (plantText , ciphertext )
44
- plantText = PKCS7UnPadding (plantText , block .BlockSize ())
45
- return plantText , nil
37
+ // AESDecrypt AES解密
38
+ func AESDecrypt (cipherBytes , key , iv []byte ) ([]byte , error ) {
39
+ block , err := aes .NewCipher (key )
40
+ if err != nil {
41
+ return nil , err
42
+ }
43
+ blockModel := cipher .NewCBCDecrypter (block , iv )
44
+ dst := make ([]byte , len (cipherBytes ))
45
+ blockModel .CryptBlocks (dst , cipherBytes )
46
+ dst = PKCS7UnPadding (dst , block .BlockSize ())
47
+ return dst , nil
46
48
}
47
49
48
- func PKCS7UnPadding (plantText []byte , blockSize int ) []byte {
49
- length := len (plantText )
50
- unpadding := int (plantText [length - 1 ])
51
- return plantText [:(length - unpadding )]
50
+ // PKCS7UnPadding pkcs7填充方式
51
+ func PKCS7UnPadding (dst []byte , blockSize int ) []byte {
52
+ length := len (dst )
53
+ unpadding := int (dst [length - 1 ])
54
+ return dst [:(length - unpadding )]
52
55
}
0 commit comments