File qmc.cc
Go to the documentation of this file
#include <qqmusic/crypto/cipher_map.h>
#include <qqmusic/crypto/cipher_rc4.h>
#include <qqmusic/crypto/cipher_tea.h>
#include <qqmusic/crypto/key_derive.h>
#include <qqmusic/crypto/qmc.h>
#include <qqmusic/details/result.h>
#include <qqmusic/utils/buffer.h>
namespace qqmusic::crypto {
Result<qqmusic::utils::buffer> Decoder::decrypt(std::string_view ekey,
qqmusic::utils::buffer&& buf) {
buf_in.swap(buf);
buf_out.clear();
qqmusic::utils::buffer ekey_buf = qqmusic::utils::buffer((uint8_t*) ekey.data(), ekey.size());
auto key = qqmusic::crypto::KeyDerive::derive(std::move(ekey_buf));
if (key.size() > 300) {
cipher = std::make_unique<RC4Cipher>(key);
cipher->decrypt(buf_in, 0);
buf_out.insert(buf_out.end(), buf_in.begin(), buf_in.end());
} else if (!key.empty()) {
cipher = std::make_unique<MapCipher>(key);
cipher->decrypt(buf_in, 0);
buf_out.insert(buf_out.end(), buf_in.begin(), buf_in.end());
} else {
return Err(utils::Exception(utils::Exception::UnknownError,
"Decoder decrypt failed! key size abnormal!"));
}
return Ok(buf_out);
}
} // namespace qqmusic::crypto