init: dec-music 项目初始化

This commit is contained in:
2026-05-23 12:55:48 +08:00
commit 21045d0aad
50 changed files with 3662 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
package crypto
import "crypto/aes"
// PKCS7UnPadding removes PKCS#7 padding.
func PKCS7UnPadding(encrypt []byte) []byte {
length := len(encrypt)
if length == 0 {
return encrypt
}
unPadding := int(encrypt[length-1])
if unPadding <= 0 || unPadding > length {
return encrypt
}
return encrypt[:length-unPadding]
}
// DecryptAES128ECB decrypts data with AES-128 ECB (block size 16).
func DecryptAES128ECB(data, key []byte) []byte {
cipher, err := aes.NewCipher(key)
if err != nil {
return nil
}
decrypted := make([]byte, len(data))
size := aes.BlockSize
for bs, be := 0, size; bs < len(data); bs, be = bs+size, be+size {
if be > len(data) {
break
}
cipher.Decrypt(decrypted[bs:be], data[bs:be])
}
return decrypted
}