AesEncrypt AES encryption, CBC
(origData, key []byte)
| 100 | |
| 101 | // AesEncrypt AES encryption, CBC |
| 102 | func AesEncrypt(origData, key []byte) ([]byte, errors.Error) { |
| 103 | // data alignment fill and encryption |
| 104 | sha256Key := sha256.Sum256(key) |
| 105 | key = sha256Key[:] |
| 106 | block, err := aes.NewCipher(key) |
| 107 | if err != nil { |
| 108 | return nil, errors.Convert(err) |
| 109 | } |
| 110 | // data alignment fill and encryption |
| 111 | blockSize := block.BlockSize() |
| 112 | origData = PKCS7Padding(origData, blockSize) |
| 113 | blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) |
| 114 | crypted := make([]byte, len(origData)) |
| 115 | blockMode.CryptBlocks(crypted, origData) |
| 116 | return crypted, nil |
| 117 | } |
| 118 | |
| 119 | // AesDecrypt AES decryption |
| 120 | func AesDecrypt(crypted, key []byte) ([]byte, errors.Error) { |
no test coverage detected