Files
Thorgathis acd50280bc Yandex Music client for Apple TV
tvOS 17+ SwiftUI client for the unofficial Yandex Music API: rotor stations
with feedback, library, search, artist and album pages, synced lyrics, and
system Now Playing integration.
2026-09-17 20:38:19 +03:00

24 lines
878 B
Swift

import CryptoKit
import Foundation
enum Crypto {
/// md5 hex digest, used by the legacy `download-info` signing scheme.
static func md5Hex(_ string: String) -> String {
let digest = Insecure.MD5.hash(data: Data(string.utf8))
return digest.map { String(format: "%02x", $0) }.joined()
}
/// base64(hmac-sha256(key, message)).
///
/// `get-file-info` wants the trailing "=" padding stripped; the lyrics
/// endpoint wants it kept.
static func hmacSHA256Base64(message: String, key: String, stripPadding: Bool = true) -> String {
let mac = HMAC<SHA256>.authenticationCode(
for: Data(message.utf8),
using: SymmetricKey(data: Data(key.utf8))
)
let encoded = Data(mac).base64EncodedString()
return stripPadding ? encoded.replacingOccurrences(of: "=", with: "") : encoded
}
}