2021.10.1 Switch AES-CBC to AES-GCM Faster(serial computing to parallel computing) and safer(avoid Padding Oracle Attack)
(key []byte)
| 12 | // Faster(serial computing to parallel computing) and safer(avoid Padding Oracle Attack) |
| 13 | |
| 14 | func KeyPadding(key []byte) []byte { |
| 15 | // if no key,just return |
| 16 | if string(key) == "" { |
| 17 | return nil |
| 18 | } |
| 19 | // if key is set & == 32 bytes, return it |
| 20 | keyLength := len(key) |
| 21 | if keyLength > 32 { |
| 22 | return key[:32] |
| 23 | } |
| 24 | // if key < 32 bytes, pad it |
| 25 | padding := 32 - keyLength |
| 26 | padText := bytes.Repeat([]byte{byte(0)}, padding) |
| 27 | return append(key, padText...) |
| 28 | } |
| 29 | |
| 30 | func genNonce(nonceSize int) []byte { |
| 31 | nonce := make([]byte, nonceSize) |
no outgoing calls
no test coverage detected