refactor: disambiguate blowfish crypto helper names

This commit is contained in:
Mathis Maquenne
2026-07-29 11:28:39 +02:00
parent 163fa18845
commit 465f54e466
2 changed files with 10 additions and 10 deletions
+8 -8
View File
@@ -9,31 +9,31 @@ import (
) )
var ( var (
iv = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07} blowfishIV = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}
secretKey = []byte("g4el58wc0zvf9na1") blowfishSecretKey = []byte("g4el58wc0zvf9na1")
) )
func GetKey(songID string) []byte { func GetBlowfishKey(songID string) []byte {
hash := md5.Sum([]byte(songID)) hash := md5.Sum([]byte(songID))
hashHex := hex.EncodeToString(hash[:]) hashHex := hex.EncodeToString(hash[:])
key := make([]byte, len(secretKey)) key := make([]byte, len(blowfishSecretKey))
copy(key, secretKey) copy(key, blowfishSecretKey)
for i := 0; i < len(hash); i++ { for i := range len(hash) {
key[i] = key[i] ^ hashHex[i] ^ hashHex[i+16] key[i] = key[i] ^ hashHex[i] ^ hashHex[i+16]
} }
return key return key
} }
func Decrypt(data, key []byte) ([]byte, error) { func DecryptBlowfish(data, key []byte) ([]byte, error) {
block, err := blowfish.NewCipher(key) block, err := blowfish.NewCipher(key)
if err != nil { if err != nil {
return nil, err return nil, err
} }
decrypted := make([]byte, len(data)) decrypted := make([]byte, len(data))
cipher.NewCBCDecrypter(block, iv).CryptBlocks(decrypted, data) cipher.NewCBCDecrypter(block, blowfishIV).CryptBlocks(decrypted, data)
return decrypted, nil return decrypted, nil
} }
+2 -2
View File
@@ -175,7 +175,7 @@ func (c *Client) downloadSong(ctx context.Context, resource deezer.Resource, son
fileName := song.GetFileName(c.resourceType, mediaFormat) fileName := song.GetFileName(c.resourceType, mediaFormat)
outputPath := path.Join(outputDir, fileName) outputPath := path.Join(outputDir, fileName)
key := crypto.GetKey(song.ID) key := crypto.GetBlowfishKey(song.ID)
if err := c.streamToFile(dlCtx, stream, outputPath, key); err != nil { if err := c.streamToFile(dlCtx, stream, outputPath, key); err != nil {
fileutil.DeleteFile(outputPath) fileutil.DeleteFile(outputPath)
return downloadResult{err: fmt.Errorf("failed to stream to file: %w", err)} return downloadResult{err: fmt.Errorf("failed to stream to file: %w", err)}
@@ -233,7 +233,7 @@ func (c *Client) streamToFile(ctx context.Context, stream io.ReadCloser, outputP
} }
if chunk%3 == 0 && totalRead == chunkSize { if chunk%3 == 0 && totalRead == chunkSize {
buffer, err = crypto.Decrypt(buffer, key) buffer, err = crypto.DecryptBlowfish(buffer, key)
if err != nil { if err != nil {
return err return err
} }