diff options
author | rsiddharth <s@ricketyspace.net> | 2020-12-06 16:11:49 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-12-06 16:11:49 -0500 |
commit | f1297ed8020ad97495f38583dbdb4a35ae3c678d (patch) | |
tree | 434537d716385b9ff5c63e954adeb040c19da0d7 | |
parent | db55bba1430939130be9aad3e4d54f901b0fac79 (diff) |
lib/aes: add AESEncryptCBC
-rw-r--r-- | lib/aes.go | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -3,6 +3,23 @@ package lib +func AESEncryptCBC(plain, key, iv []byte) []byte { + iter := len(plain) / 16 + + lc := iv + output := make([]byte, 0) + for i := 0; i < iter; i++ { + s := (i * 16) + e := (i * 16) + 16 + p := plain[s:e] + c := aesCipher(FixedXORBytes(p, lc), key) + output = append(output, c...) + + lc = c + } + return output +} + func AESDecryptCBC(cipher, key, iv []byte) []byte { iter := len(cipher) / 16 @@ -46,7 +63,6 @@ func AESDecryptECB(cipher, key []byte) []byte { return output } - func aesCipher(in, ky []byte) []byte { nb := 4 nr := 10 |