66 "crypto/cipher"
77)
88
9- // AesECBEncrypt
9+ // AesECBEncrypt encrypts data using the ECB mode of the AES algorithm.
1010func AesECBEncrypt (src , key []byte , padding string ) ([]byte , error ) {
1111 block , err := AesNewCipher (key )
1212 if err != nil {
@@ -15,7 +15,7 @@ func AesECBEncrypt(src, key []byte, padding string) ([]byte, error) {
1515 return ECBEncrypt (block , src , padding )
1616}
1717
18- // AesECBDecrypt
18+ // AesECBDecrypt decrypts data using the ECB mode of the AES algorithm.
1919func AesECBDecrypt (src , key []byte , padding string ) ([]byte , error ) {
2020 block , err := AesNewCipher (key )
2121 if err != nil {
@@ -25,7 +25,7 @@ func AesECBDecrypt(src, key []byte, padding string) ([]byte, error) {
2525 return ECBDecrypt (block , src , padding )
2626}
2727
28- // AesCBCEncrypt
28+ // AesCBCEncrypt encrypts data using the CBC mode of the AES algorithm.
2929func AesCBCEncrypt (src , key , iv []byte , padding string ) ([]byte , error ) {
3030 block , err := AesNewCipher (key )
3131 if err != nil {
@@ -35,7 +35,7 @@ func AesCBCEncrypt(src, key, iv []byte, padding string) ([]byte, error) {
3535 return CBCEncrypt (block , src , iv , padding )
3636}
3737
38- // AesCBCDecrypt
38+ // AesCBCDecrypt decrypts data using the CBC mode of the AES algorithm.
3939func AesCBCDecrypt (src , key , iv []byte , padding string ) ([]byte , error ) {
4040 block , err := AesNewCipher (key )
4141 if err != nil {
@@ -45,13 +45,12 @@ func AesCBCDecrypt(src, key, iv []byte, padding string) ([]byte, error) {
4545 return CBCDecrypt (block , src , iv , padding )
4646}
4747
48- // AesNewCipher creates and returns a new AES cipher.Block.
49- // it will automatically pad the length of the key.
48+ // AesNewCipher creates and returns a new AES cipher block. Automatically pads the key length.
5049func AesNewCipher (key []byte ) (cipher.Block , error ) {
5150 return aes .NewCipher (aesKeyPending (key ))
5251}
5352
54- // aesKeyPending The length of the key can be 16/24/ 32 characters (128/ 192/ 256 bits)
53+ // aesKeyPending ensures the key length is 16, 24, or 32 bytes (128, 192, or 256 bits).
5554func aesKeyPending (key []byte ) []byte {
5655 k := len (key )
5756 count := 0
0 commit comments