init: dec-music 项目初始化
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user