默然云后台管理系统
APIpost文档
APIpost文档
  1. 必看
  • 更新日志
  • 必看
    • 必看文档!!!
    • 获取当前时间戳
    • 输出数据解密
    • 生成签名
    • 更新日志
      GET
    • 必看文档
      GET
    • 生成签名
      GET
  • APP相关
    • 获取APP信息
      POST
    • 获取APP更新记录
      POST
    • 增加APP访问量
      POST
    • 获取APP相关统计数据
      POST
    • 利用appkey 增减 用户金币或积分 会员天数
      POST
  • 用户相关
    • 用户登录
      POST
    • 获取图片验证码
      POST
    • 手机号登录
      POST
    • 获取短信验证码
      POST
    • 用户注册
      POST
    • 获取邮箱验证码
      POST
    • 用户心跳
      POST
    • 退出登录
      POST
    • 获取用户信息
      POST
    • 获取登录用户的全部信息
      POST
    • 用户签到
      POST
    • 找回密码
      POST
    • 上传头像
      POST
    • 上传背景
      POST
    • 修改密码
      POST
    • 修改用户信息
      POST
    • 修改用户邮箱
      POST
    • 修改手机号
      POST
    • 填写邀请码
      POST
    • 积分排行榜
      POST
    • 邀请排行榜
      POST
    • 取消关注用户
      POST
    • 查询关注列表
      POST
    • 查询粉丝列表
      POST
    • 获取用户账单
      POST
    • 查询关注状态
      POST
    • QQ登录
      POST
    • 用户提现
      POST
    • 绑定QQ登录
      POST
    • 获取用户提现记录
      POST
    • qq一键注册并登录
      POST
    • 解绑QQ
      POST
  • 卡密相关
    • 使用直冲卡密
    • 使用登录卡密
    • 卡密自动登录
  • 商城相关
    • 商品列表
    • 获取商品信息
    • 购买商品
    • 获取订单记录
  • 论坛相关
    • 获取板块列表
    • 获取板块信息
    • 获取帖子列表
    • 获取推荐帖子(只有正常帖子才会推荐)
    • 获取帖子信息
    • 发布帖子
    • 删除帖子
    • 发表评论
    • 编辑帖子
    • 删除评论
    • 获取评论列表
    • 取消点赞帖子
    • 获取点赞记录
    • 浏览历史
    • 审核帖子
    • 获取待审核的帖子
    • 帖子状态修改
    • 获取我的关注的帖子
    • 打赏帖子
    • 对需要支付的帖子进行支付
    • 获取关注用户的帖子列表
    • 对评论的打赏
    • 取消收藏帖子
    • 获取收藏记录
    • 获取举报标签
    • 举报帖子或评论
    • 获取用户举报记录
    • 获取待审核评论列表
    • 审核评论
  • 消息通知
    • 获取消息通知
    • 获取未读消息通知数量
    • 一键清除消息通知
  • 笔记管理
    • 获取用户笔记
    • 获取用户笔记详情
    • 修改笔记
    • 删除笔记
    • 添加笔记
  • 私聊系统
    • 发送消息
    • 获取用户消息列表
    • 获取聊天记录
  • 应用商店
    • 获取应用分类列表
    • 获取分类的下级分类列表
    • 获取应用列表
    • 获取应用详情
    • 获取该应用的历史版本
    • 发布应用
    • 发布新版本
    • 修改应用信息
    • 获取用户自己已上传的应用列表
    • 获取评论列表
    • 发表评论
    • 删除应用或应用版本
    • 删除评论
    • 增加下载量
    • 对需要支付的应用进行支付
    • 对应用打赏
  • 发送邮件接口
    POST
  • 上传返回直链
    POST
  1. 必看

输出数据解密

输出数据进行加密的目的是确保数据的安全性和完整性。

  • 防止数据篡改:通过对输出数据进行加密,可以防止数据在传输过程中被篡改或修改。加密可以提供数据的完整性验证,确保数据在传输过程中没有被恶意篡改。
  • 增强数据安全性:通过加密输出数据,即使数据意外泄露或暴露,未经授权的人员也无法直接访问和理解数据内容。这可以增强数据的安全性,降低数据泄露的风险。

Base64解密

PHP:

php

注:密钥和向量是同一个 php: php $decrypted = openssl_decrypt($encryptedData, 'AES-128-CBC', $key, OPENSSL_RAW_DATA); java: java import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.util.Base64; public class AESDecryptor { public static String decrypt(String encryptedText, String key, String iv) throws Exception { byte[] encryptedData = Base64.getDecoder().decode(encryptedText); byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); byte[] ivBytes = iv.getBytes(StandardCharsets.UTF_8); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivSpec); byte[] decryptedData = cipher.doFinal(encryptedData); return new String(decryptedData, StandardCharsets.UTF_8); } public static void main(String[] args) { String encryptedText = "需要解密的数据"; String key = "你的key"; String iv = "初始化向量"; try { String decryptedText = decrypt(encryptedText, key, iv); System.out.println("解密后: " + decryptedText); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } c++: #include #include #include #include #include #include #include #include std::string base64_decode(const std::string &in) { std::string out; EVP_ENCODE_CTX ectx; EVP_DecodeInit(&ectx); int out_len = in.size() * 3 / 4 + 1; int in_len = in.size(); int final_len = 0; unsigned char *buffer = new unsigned char[out_len]; EVP_DecodeUpdate(&ectx, buffer, &out_len, reinterpret_cast(in.c_str()), in_len); out.append(reinterpret_cast(buffer), out_len); EVP_DecodeFinal(&ectx, buffer, &final_len); out.append(reinterpret_cast(buffer), final_len); delete[] buffer; return out; } std::string aes_decrypt(const std::string &key, const std::string &iv, const std::string &enc) { EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); if (!ctx) throw std::runtime_error("Couldn't create Cipher Context"); if (EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, reinterpret_cast(key.c_str()), reinterpret_cast(iv.c_str())) != 1) throw std::runtime_error("Couldn't initialize Cipher Context"); std::string enc_bin = base64_decode(enc); int len = enc_bin.size(); int plaintext_len = len; unsigned char *plaintext = new unsigned char[plaintext_len]; if (EVP_DecryptUpdate(ctx, plaintext, &len, reinterpret_cast(enc_bin.c_str()), enc_bin.size()) != 1) throw std::runtime_error("Error during decryption"); plaintext_len = len; if (EVP_DecryptFinal_ex(ctx, plaintext + len, &len) != 1) throw std::runtime_error("Error during final decryption"); plaintext_len += len; EVP_CIPHER_CTX_free(ctx); std::string ret(reinterpret_cast(plaintext), plaintext_len); delete[] plaintext; return ret; } int main() { std::string encryptedText = "需要解密的数据"; std::string key = "你的key"; std::string iv = "初始化向量"; try { std::string decryptedText = aes_decrypt(key, iv, encryptedText); std::cout << "Decrypted text: " << decryptedText << std::endl; } catch (std::exception &e) { std::cout << "Error: " << e.what() << std::endl; } return 0; } JavaScript: const crypto = require('crypto'); function decrypt(encryptedText, key, iv) { let encryptedData = Buffer.from(encryptedText, 'base64'); let decipher = crypto.createDecipheriv('aes-128-cbc', Buffer.from(key, 'utf8'), Buffer.from(iv, 'utf8')); let decryptedData = Buffer.concat([decipher.update(encryptedData), decipher.final()]); return decryptedData.toString('utf8'); } let encryptedText = "需要解密的数据"; let key = "你的key"; let iv = "初始化向量"; try { let decryptedText = decrypt(encryptedText, key, iv); console.log("Decrypted text: " + decryptedText); } catch (e) { console.log("Error: " + e.message); } python: from base64 import b64decode from Crypto.Cipher import AES from Crypto.Util.Padding import unpad def decrypt(encrypted_text, key, iv): encrypted_data = b64decode(encrypted_text) cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8')) decrypted_data = unpad(cipher.decrypt(encrypted_data), AES.block_size) return decrypted_data.decode('utf-8') encrypted_text = "需要解密的数据" key = "你的key" iv = "初始化向量" try: decrypted_text = decrypt(encrypted_text, key, iv) print("Decrypted text: " + decrypted_text) except Exception as e: print("Error: " + str(e)) c#: using System; using System.Security.Cryptography; using System.Text; public class AESDecryptor { public static string Decrypt(string encryptedText, string key, string iv) { byte[] encryptedData = Convert.FromBase64String(encryptedText); byte[] keyBytes = Encoding.UTF8.GetBytes(key); byte[] ivBytes = Encoding.UTF8.GetBytes(iv); using (Aes aes = Aes.Create()) { aes.Key = keyBytes; aes.IV = ivBytes; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); byte[] decryptedData = decryptor.TransformFinalBlock(encryptedData, 0, encryptedData.Length); return Encoding.UTF8.GetString(decryptedData); } } public static void Main() { string encryptedText = "需要解密的数据"; string key = "你的key"; string iv = "初始化向量"; try { string decryptedText = Decrypt(encryptedText, key, iv); Console.WriteLine("Decrypted text: " + decryptedText); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } } } # AES-128-ECB 解密 > 注:若使用aes加密,推荐使用cbc模式加密,数据更安全,这里不提供过多ecb解密方法 > php: php $decrypted = openssl_decrypt($encryptedData, 'AES-128-ECB', $key, OPENSSL_RAW_DATA); java: java import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.util.Base64; public class AESDecryptor { public static String decrypt(String encryptedText, String key) throws Exception { byte[] encryptedData = Base64.getDecoder().decode(encryptedText); byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] decryptedData = cipher.doFinal(encryptedData); return new String(decryptedData, StandardCharsets.UTF_8); } public static void main(String[] args) { String encryptedText = "需要解密的数据"; String key = "你的key"; try { String decryptedText = decrypt(encryptedText, key); System.out.println("解密后: " + decryptedText); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } # DES-ECB 解密 php: php $decrypted = openssl_decrypt($encryptedData, 'DES-ECB', $key, OPENSSL_RAW_DATA); java: java import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.util.Base64; public class DESDecryptor { public static String decrypt(String encryptedText, String key) throws Exception { byte[] encryptedData = Base64.getDecoder().decode(encryptedText); byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES"); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] decryptedData = cipher.doFinal(encryptedData); return new String(decryptedData, StandardCharsets.UTF_8); } public static void main(String[] args) { String encryptedText = "需要解密的数据"; String key = "你的key"; try { String decryptedText = decrypt(encryptedText, key); System.out.println("解密后: " + decryptedText); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } c++: #include #include #include #include #include #include #include std::string base64_decode(const std::string& encoded_string) { BIO *bio, *b64; BUF_MEM *bufferPtr; bio = BIO_new_mem_buf(encoded_string.c_str(), -1); b64 = BIO_new(BIO_f_base64()); bio = BIO_push(b64, bio); BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); BIO_flush(bio); BIO_get_mem_ptr(bio, &bufferPtr); std::string decoded_string(bufferPtr->data, bufferPtr->length); BIO_free_all(bio); return decoded_string; } std::string decrypt(std::string encryptedText, std::string key) { encryptedText = base64_decode(encryptedText); unsigned char keyBytes[8]; memset(keyBytes, 0, 8); memcpy(keyBytes, key.c_str(), key.length()); DES_cblock keyEncrypt; DES_key_schedule schedule; memcpy(keyEncrypt, keyBytes, 8); DES_set_key_unchecked(&keyEncrypt, &schedule); std::string decryptedText; unsigned char input[encryptedText.length()]; memset(input, 0, encryptedText.length()); memcpy(input, encryptedText.c_str(), encryptedText.length()); unsigned char output[encryptedText.length()]; memset(output, 0, encryptedText.length()); DES_ecb_encrypt((C_Block *)input, (C_Block *)output, &schedule, DES_DECRYPT); decryptedText = std::string((char*)output); return decryptedText; } int main() { std::string encryptedText = "需要解密的数据"; std::string key = "你的key"; try { std::string decryptedText = decrypt(encryptedText, key); std::cout << "解密后: " << decryptedText << std::endl; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } } js: function decrypt(encryptedText, key) { const keyBytes = new TextEncoder().encode(key); const encryptedBytes = Uint8Array.from(atob(encryptedText), c => c.charCodeAt(0)); const decipher = window.crypto.subtle.decrypt( { name: "DES-ECB", iv: new Uint8Array(0), }, keyBytes, encryptedBytes ); return decipher.then((decryptedBytes) => { return new TextDecoder().decode(decryptedBytes); }); } const encryptedText = "需要解密的数据"; const key = "你的key"; decrypt(encryptedText, key).then((decryptedText) => { console.log("解密后: " + decryptedText); }).catch((e) => { console.error("Error: " + e.message); }); # RC4 解密 php: php /** * RC4位置替换 * @param $a * @param $b */ public function swap(&$a, &$b) { $tmp = $a; $a = $b; $b = $tmp; } /** * RC4 解密 * @param $key 密钥 * @param $data 待加密的数据 * @return string */ public function encrypted($data, $key) { $keyLength = strlen($key); $S = array(); for ($i = 0; $i < 256; $i++) $S[$i] = $i; $j = 0; for ($i = 0; $i < 256; $i++) { $j = ($j + $S[$i] + ord($key[$i % $keyLength])) % 256; $this->swap($S[$i], $S[$j]); } $dataLength = strlen($data); $output = ""; for ($a = $j = $i = 0; $i < $dataLength; $i++) { $a = ($a + 1) % 256; $j = ($j + $S[$a]) % 256; $this->swap($S[$a], $S[$j]); $k = $S[(($S[$a] + $S[$j]) % 256)]; $output .= chr(ord($data[$i]) ^ $k); } return $output; } java: java import java.io.UnsupportedEncodingException; public class RC4EncryptDecrypt { public static void main(String[] args) { String data = "需要解密的数据"; String key = "你的key"; String chartSet = "UTF-8"; try { String decryData = decryRC4(data, key, chartSet); System.out.println("解密后的数据:" + decryData); } catch (UnsupportedEncodingException e) { System.out.println("解密失败:" + e.getMessage()); } } /** * RC4解密 * * @param data 需要解密的数据 * @param key 加密密钥 * @param chartSet 编码方式 * @return 返回解密后的数据 * @throws UnsupportedEncodingException */ public static String decryRC4(String data, String key, String chartSet) throws UnsupportedEncodingException { if (data == null || key == null) { return null; } return new String(RC4Base(hexToByte(data), key), chartSet); } /** * RC4加密初始化密钥 * * @param aKey * @return */ private static byte[] initKey(String aKey) { byte[] bkey = aKey.getBytes(); byte state[] = new byte[256]; for (int i = 0; i < 256; i++) { state[i] = (byte) i; } int index1 = 0; int index2 = 0; if (bkey.length == 0) { return null; } for (int i = 0; i < 256; i++) { index2 = ((bkey[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff; byte tmp = state[i]; state[i] = state[index2]; state[index2] = tmp; index1 = (index1 + 1) % bkey.length; } return state; } /** * 十六进制转字节数组 * * @return */ public static byte[] hexToByte(String inHex) { int hexlen = inHex.length(); byte[] result; if (hexlen % 2 == 1) { hexlen++; result = new byte[(hexlen / 2)]; inHex = "0" + inHex; } else { result = new byte[(hexlen / 2)]; } int j = 0; for (int i = 0; i < hexlen; i += 2) { result[j] = (byte) Integer.parseInt(inHex.substring(i, i + 2), 16); j++; } return result; } /** * RC4解密 * * @param input * @param mKkey * @return */ private static byte[] RC4Base(byte[] input, String mKkey) { int x = 0; int y = 0; byte key[] = initKey(mKkey); int xorIndex; byte[] result = new byte[input.length]; for (int i = 0; i < input.length; i++) { x = (x + 1) & 0xff; y = ((key[x] & 0xff) + y) & 0xff; byte tmp = key[x]; key[x] = key[y]; key[y] = tmp; xorIndex = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff; result[i] = (byte) (input[i] ^ key[xorIndex]); } return result; } } c++: #include #include #include #include #include std::vector initKey(const std::string& aKey) { std::vector bkey(aKey.begin(), aKey.end()); std::vector state(256); for (int i = 0; i < 256; i++) { state[i] = i; } int index1 = 0; int index2 = 0; if (bkey.empty()) { return {}; } for (int i = 0; i < 256; i++) { index2 = ((bkey[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff; std::swap(state[i], state[index2]); index1 = (index1 + 1) % bkey.size(); } return state; } std::vector hexToByte(const std::string& inHex) { std::string hex = inHex; int hexlen = hex.length(); std::vector result; if (hexlen % 2 == 1) { hexlen++; result.resize(hexlen / 2); hex = "0" + hex; } else { result.resize(hexlen / 2); } for (int i = 0, j = 0; i < hexlen; i += 2, j++) { std::string byteString = hex.substr(i, 2); unsigned char byte = std::strtol(byteString.c_str(), nullptr, 16); result[j] = byte; } return result; } std::vector RC4Base(const std::vector& input, const std::string& mKkey) { int x = 0; int y = 0; std::vector key = initKey(mKkey); int xorIndex; std::vector result(input.size()); for (int i = 0; i < input.size(); i++) { x = (x + 1) & 0xff; y = ((key[x] & 0xff) + y) & 0xff; std::swap(key[x], key[y]); xorIndex = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff; result[i] = input[i] ^ key[xorIndex]; } return result; } std::string decryRC4(const std::string& data, const std::string& key) { if (data.empty() || key.empty()) { return ""; } std::vector decrypted = RC4Base(hexToByte(data), key); std::string result(decrypted.begin(), decrypted.end()); return result; } int main() { std::string data = "需要解密的数据"; std::string key = "你的key"; std::string decryData = decryRC4(data, key); std::cout << "Decrypted data: " << decryData << std::endl; return 0; } python: #这段代码仅支持Python3,Python2仅需略微修改即可使用 import codecs def init_key(a_key): b_key = [ord(c) for c in a_key] state = [i for i in range(256)] index1 = 0 index2 = 0 if len(b_key) == 0: return None for i in range(256): index2 = ((b_key[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff state[i], state[index2] = state[index2], state[i] index1 = (index1 + 1) % len(b_key) return state def hex_to_byte(in_hex): hexlen = len(in_hex) if hexlen % 2 == 1: hexlen += 1 in_hex = "0" + in_hex result = bytearray.fromhex(in_hex) return result def RC4_base(input, m_key): x = y = xor_index = 0 key = init_key(m_key) result = bytearray(len(input)) for i in range(len(input)): x = (x + 1) & 0xff y = ((key[x] & 0xff) + y) & 0xff key[x], key[y] = key[y], key[x] xor_index = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff result[i] = input[i] ^ key[xor_index] return result def decry_RC4(data, key, charset): if data is None or key is None: return None data_bytes = bytes.fromhex(data) decry_data = RC4_base(data_bytes, key) return decry_data.decode(charset) def main(): data = "需要解密的数据" key = "你的key" charset = "UTF-8" try: decry_data = decry_RC4(data, key, charset) print("Decrypted data: " + decry_data) except Exception as e: print("Decryption failed: " + str(e)) if __name__ == "__main__": main() JavaScript: const { TextEncoder, TextDecoder } = require('util'); function main() { const data = "需要解密的数据"; const key = "你的密钥"; const chartSet = "UTF-8"; try { const decryData = decryRC4(data, key, chartSet); console.log(解密后的数据:${decryData}); } catch (e) { console.log(解密失败:${e.message}); } } function decryRC4(data, key, chartSet) { if (!data || !key) { return null; } const decryData = RC4Base(hexToByte(data), key); return new TextDecoder(chartSet).decode(Buffer.from(decryData)); } function initKey(aKey) { const bkey = new TextEncoder().encode(aKey); const state = Buffer.alloc(256); for (const i of state.keys()) { state[i] = i; } let index1 = 0; let index2 = 0; if (bkey.length === 0) { return null; } for (const i of state.keys()) { index2 = ((bkey[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff; [state[i], state[index2]] = [state[index2], state[i]]; index1 = (index1 + 1) % bkey.length; } return state; } function hexToByte(inHex) { const hexlen = inHex.length; let result; if (hexlen % 2 === 1) { hexlen++; result = Buffer.alloc(hexlen / 2); inHex = "0" + inHex; } else { result = Buffer.alloc(hexlen / 2); } let j = 0; for (let i = 0; i < hexlen; i += 2) { result[j++] = parseInt(inHex.substring(i, i + 2), 16); } return result; } function RC4Base(input, mKkey) { let x = 0; let y = 0; const key = initKey(mKkey); let xorIndex; const result = Buffer.alloc(input.length); for (const i of input.keys()) { x = (x + 1) & 0xff; y = ((key[x] & 0xff) + y) & 0xff; [key[x], key[y]] = [key[y], key[x]]; xorIndex = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff; result[i] = input[i] ^ key[xorIndex]; } return result; } if (require.main === module) { main(); } > 输出数据进行加密的目的是确保数据的安全性和完整性。 - 防止数据篡改:通过对输出数据进行加密,可以防止数据在传输过程中被篡改或修改。加密可以提供数据的完整性验证,确保数据在传输过程中没有被恶意篡改。 - 增强数据安全性:通过加密输出数据,即使数据意外泄露或暴露,未经授权的人员也无法直接访问和理解数据内容。这可以增强数据的安全性,降低数据泄露的风险。 # Base64解密 PHP: php 注:密钥和向量是同一个 php: php $decrypted = openssl_decrypt($encryptedData, 'AES-128-CBC', $key, OPENSSL_RAW_DATA); java: java import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.util.Base64; public class AESDecryptor { public static String decrypt(String encryptedText, String key, String iv) throws Exception { byte[] encryptedData = Base64.getDecoder().decode(encryptedText); byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); byte[] ivBytes = iv.getBytes(StandardCharsets.UTF_8); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivSpec); byte[] decryptedData = cipher.doFinal(encryptedData); return new String(decryptedData, StandardCharsets.UTF_8); } public static void main(String[] args) { String encryptedText = "需要解密的数据"; String key = "你的key"; String iv = "初始化向量"; try { String decryptedText = decrypt(encryptedText, key, iv); System.out.println("解密后: " + decryptedText); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } c++: #include #include #include #include #include #include #include #include std::string base64_decode(const std::string &in) { std::string out; EVP_ENCODE_CTX ectx; EVP_DecodeInit(&ectx); int out_len = in.size() * 3 / 4 + 1; int in_len = in.size(); int final_len = 0; unsigned char *buffer = new unsigned char[out_len]; EVP_DecodeUpdate(&ectx, buffer, &out_len, reinterpret_cast(in.c_str()), in_len); out.append(reinterpret_cast(buffer), out_len); EVP_DecodeFinal(&ectx, buffer, &final_len); out.append(reinterpret_cast(buffer), final_len); delete[] buffer; return out; } std::string aes_decrypt(const std::string &key, const std::string &iv, const std::string &enc) { EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); if (!ctx) throw std::runtime_error("Couldn't create Cipher Context"); if (EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, reinterpret_cast(key.c_str()), reinterpret_cast(iv.c_str())) != 1) throw std::runtime_error("Couldn't initialize Cipher Context"); std::string enc_bin = base64_decode(enc); int len = enc_bin.size(); int plaintext_len = len; unsigned char *plaintext = new unsigned char[plaintext_len]; if (EVP_DecryptUpdate(ctx, plaintext, &len, reinterpret_cast(enc_bin.c_str()), enc_bin.size()) != 1) throw std::runtime_error("Error during decryption"); plaintext_len = len; if (EVP_DecryptFinal_ex(ctx, plaintext + len, &len) != 1) throw std::runtime_error("Error during final decryption"); plaintext_len += len; EVP_CIPHER_CTX_free(ctx); std::string ret(reinterpret_cast(plaintext), plaintext_len); delete[] plaintext; return ret; } int main() { std::string encryptedText = "需要解密的数据"; std::string key = "你的key"; std::string iv = "初始化向量"; try { std::string decryptedText = aes_decrypt(key, iv, encryptedText); std::cout << "Decrypted text: " << decryptedText << std::endl; } catch (std::exception &e) { std::cout << "Error: " << e.what() << std::endl; } return 0; } //Author:QingJ JavaScript: const crypto = require('crypto'); function decrypt(encryptedText, key, iv) { let encryptedData = Buffer.from(encryptedText, 'base64'); let decipher = crypto.createDecipheriv('aes-128-cbc', Buffer.from(key, 'utf8'), Buffer.from(iv, 'utf8')); let decryptedData = Buffer.concat([decipher.update(encryptedData), decipher.final()]); return decryptedData.toString('utf8'); } let encryptedText = "需要解密的数据"; let key = "你的key"; let iv = "初始化向量"; try { let decryptedText = decrypt(encryptedText, key, iv); console.log("Decrypted text: " + decryptedText); } catch (e) { console.log("Error: " + e.message); } python: from base64 import b64decode from Crypto.Cipher import AES from Crypto.Util.Padding import unpad def decrypt(encrypted_text, key, iv): encrypted_data = b64decode(encrypted_text) cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8')) decrypted_data = unpad(cipher.decrypt(encrypted_data), AES.block_size) return decrypted_data.decode('utf-8') encrypted_text = "需要解密的数据" key = "你的key" iv = "初始化向量" try: decrypted_text = decrypt(encrypted_text, key, iv) print("Decrypted text: " + decrypted_text) except Exception as e: print("Error: " + str(e)) # Author:QingJ c#: using System; using System.Security.Cryptography; using System.Text; public class AESDecryptor { public static string Decrypt(string encryptedText, string key, string iv) { byte[] encryptedData = Convert.FromBase64String(encryptedText); byte[] keyBytes = Encoding.UTF8.GetBytes(key); byte[] ivBytes = Encoding.UTF8.GetBytes(iv); using (Aes aes = Aes.Create()) { aes.Key = keyBytes; aes.IV = ivBytes; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); byte[] decryptedData = decryptor.TransformFinalBlock(encryptedData, 0, encryptedData.Length); return Encoding.UTF8.GetString(decryptedData); } } public static void Main() { string encryptedText = "需要解密的数据"; string key = "你的key"; string iv = "初始化向量"; try { string decryptedText = Decrypt(encryptedText, key, iv); Console.WriteLine("Decrypted text: " + decryptedText); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } } } # AES-128-ECB 解密 > 注:若使用aes加密,推荐使用cbc模式加密,数据更安全,这里不提供过多ecb解密方法 > php: php $decrypted = openssl_decrypt($encryptedData, 'AES-128-ECB', $key, OPENSSL_RAW_DATA); java: java import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.util.Base64; public class AESDecryptor { public static String decrypt(String encryptedText, String key) throws Exception { byte[] encryptedData = Base64.getDecoder().decode(encryptedText); byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] decryptedData = cipher.doFinal(encryptedData); return new String(decryptedData, StandardCharsets.UTF_8); } public static void main(String[] args) { String encryptedText = "需要解密的数据"; String key = "你的key"; try { String decryptedText = decrypt(encryptedText, key); System.out.println("解密后: " + decryptedText); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } # DES-ECB 解密 php: php $decrypted = openssl_decrypt($encryptedData, 'DES-ECB', $key, OPENSSL_RAW_DATA); java: java import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.util.Base64; public class DESDecryptor { public static String decrypt(String encryptedText, String key) throws Exception { byte[] encryptedData = Base64.getDecoder().decode(encryptedText); byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES"); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] decryptedData = cipher.doFinal(encryptedData); return new String(decryptedData, StandardCharsets.UTF_8); } public static void main(String[] args) { String encryptedText = "需要解密的数据"; String key = "你的key"; try { String decryptedText = decrypt(encryptedText, key); System.out.println("解密后: " + decryptedText); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } } c++: #include #include #include #include #include #include #include std::string base64_decode(const std::string& encoded_string) { BIO *bio, *b64; BUF_MEM *bufferPtr; bio = BIO_new_mem_buf(encoded_string.c_str(), -1); b64 = BIO_new(BIO_f_base64()); bio = BIO_push(b64, bio); BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); BIO_flush(bio); BIO_get_mem_ptr(bio, &bufferPtr); std::string decoded_string(bufferPtr->data, bufferPtr->length); BIO_free_all(bio); return decoded_string; } std::string decrypt(std::string encryptedText, std::string key) { encryptedText = base64_decode(encryptedText); unsigned char keyBytes[8]; memset(keyBytes, 0, 8); memcpy(keyBytes, key.c_str(), key.length()); DES_cblock keyEncrypt; DES_key_schedule schedule; memcpy(keyEncrypt, keyBytes, 8); DES_set_key_unchecked(&keyEncrypt, &schedule); std::string decryptedText; unsigned char input[encryptedText.length()]; memset(input, 0, encryptedText.length()); memcpy(input, encryptedText.c_str(), encryptedText.length()); unsigned char output[encryptedText.length()]; memset(output, 0, encryptedText.length()); DES_ecb_encrypt((C_Block *)input, (C_Block *)output, &schedule, DES_DECRYPT); decryptedText = std::string((char*)output); return decryptedText; } int main() { std::string encryptedText = "需要解密的数据"; std::string key = "你的key"; try { std::string decryptedText = decrypt(encryptedText, key); std::cout << "解密后: " << decryptedText << std::endl; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } } //Author:QingJ JavaScript: function decrypt(encryptedText, key) { const keyBytes = new TextEncoder().encode(key); const encryptedBytes = Uint8Array.from(atob(encryptedText), c => c.charCodeAt(0)); const decipher = window.crypto.subtle.decrypt( { name: "DES-ECB", iv: new Uint8Array(0), }, keyBytes, encryptedBytes ); return decipher.then((decryptedBytes) => { return new TextDecoder().decode(decryptedBytes); }); } const encryptedText = "需要解密的数据"; const key = "你的key"; decrypt(encryptedText, key).then((decryptedText) => { console.log("解密后: " + decryptedText); }).catch((e) => { console.error("Error: " + e.message); }); /** Author:QingJ */ # RC4 解密 php: php /** * RC4位置替换 * @param $a * @param $b */ public function swap(&$a, &$b) { $tmp = $a; $a = $b; $b = $tmp; } /** * RC4 解密 * @param $key 密钥 * @param $data 待加密的数据 * @return string */ public function encrypted($data, $key) { $keyLength = strlen($key); $S = array(); for ($i = 0; $i < 256; $i++) $S[$i] = $i; $j = 0; for ($i = 0; $i < 256; $i++) { $j = ($j + $S[$i] + ord($key[$i % $keyLength])) % 256; $this->swap($S[$i], $S[$j]); } $dataLength = strlen($data); $output = ""; for ($a = $j = $i = 0; $i < $dataLength; $i++) { $a = ($a + 1) % 256; $j = ($j + $S[$a]) % 256; $this->swap($S[$a], $S[$j]); $k = $S[(($S[$a] + $S[$j]) % 256)]; $output .= chr(ord($data[$i]) ^ $k); } return $output; } java: java import java.io.UnsupportedEncodingException; public class RC4EncryptDecrypt { public static void main(String[] args) { String data = "需要解密的数据"; String key = "你的key"; String chartSet = "UTF-8"; try { String decryData = decryRC4(data, key, chartSet); System.out.println("解密后的数据:" + decryData); } catch (UnsupportedEncodingException e) { System.out.println("解密失败:" + e.getMessage()); } } /** * RC4解密 * * @param data 需要解密的数据 * @param key 加密密钥 * @param chartSet 编码方式 * @return 返回解密后的数据 * @throws UnsupportedEncodingException */ public static String decryRC4(String data, String key, String chartSet) throws UnsupportedEncodingException { if (data == null || key == null) { return null; } return new String(RC4Base(hexToByte(data), key), chartSet); } /** * RC4加密初始化密钥 * * @param aKey * @return */ private static byte[] initKey(String aKey) { byte[] bkey = aKey.getBytes(); byte state[] = new byte[256]; for (int i = 0; i < 256; i++) { state[i] = (byte) i; } int index1 = 0; int index2 = 0; if (bkey.length == 0) { return null; } for (int i = 0; i < 256; i++) { index2 = ((bkey[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff; byte tmp = state[i]; state[i] = state[index2]; state[index2] = tmp; index1 = (index1 + 1) % bkey.length; } return state; } /** * 十六进制转字节数组 * * @return */ public static byte[] hexToByte(String inHex) { int hexlen = inHex.length(); byte[] result; if (hexlen % 2 == 1) { hexlen++; result = new byte[(hexlen / 2)]; inHex = "0" + inHex; } else { result = new byte[(hexlen / 2)]; } int j = 0; for (int i = 0; i < hexlen; i += 2) { result[j] = (byte) Integer.parseInt(inHex.substring(i, i + 2), 16); j++; } return result; } /** * RC4解密 * * @param input * @param mKkey * @return */ private static byte[] RC4Base(byte[] input, String mKkey) { int x = 0; int y = 0; byte key[] = initKey(mKkey); int xorIndex; byte[] result = new byte[input.length]; for (int i = 0; i < input.length; i++) { x = (x + 1) & 0xff; y = ((key[x] & 0xff) + y) & 0xff; byte tmp = key[x]; key[x] = key[y]; key[y] = tmp; xorIndex = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff; result[i] = (byte) (input[i] ^ key[xorIndex]); } return result; } } c++: #include #include #include #include #include std::vector initKey(const std::string& aKey) { std::vector bkey(aKey.begin(), aKey.end()); std::vector state(256); for (int i = 0; i < 256; i++) { state[i] = i; } int index1 = 0; int index2 = 0; if (bkey.empty()) { return {}; } for (int i = 0; i < 256; i++) { index2 = ((bkey[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff; std::swap(state[i], state[index2]); index1 = (index1 + 1) % bkey.size(); } return state; } std::vector hexToByte(const std::string& inHex) { std::string hex = inHex; int hexlen = hex.length(); std::vector result; if (hexlen % 2 == 1) { hexlen++; result.resize(hexlen / 2); hex = "0" + hex; } else { result.resize(hexlen / 2); } for (int i = 0, j = 0; i < hexlen; i += 2, j++) { std::string byteString = hex.substr(i, 2); unsigned char byte = std::strtol(byteString.c_str(), nullptr, 16); result[j] = byte; } return result; } std::vector RC4Base(const std::vector& input, const std::string& mKkey) { int x = 0; int y = 0; std::vector key = initKey(mKkey); int xorIndex; std::vector result(input.size()); for (int i = 0; i < input.size(); i++) { x = (x + 1) & 0xff; y = ((key[x] & 0xff) + y) & 0xff; std::swap(key[x], key[y]); xorIndex = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff; result[i] = input[i] ^ key[xorIndex]; } return result; } std::string decryRC4(const std::string& data, const std::string& key) { if (data.empty() || key.empty()) { return ""; } std::vector decrypted = RC4Base(hexToByte(data), key); std::string result(decrypted.begin(), decrypted.end()); return result; } int main() { std::string data = "需要解密的数据"; std::string key = "你的key"; std::string decryData = decryRC4(data, key); std::cout << "Decrypted data: " << decryData << std::endl; return 0; } //Author:QingJ python: #这段代码仅支持Python3,Python2仅需略微修改即可使用 import codecs def init_key(a_key): b_key = [ord(c) for c in a_key] state = [i for i in range(256)] index1 = 0 index2 = 0 if len(b_key) == 0: return None for i in range(256): index2 = ((b_key[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff state[i], state[index2] = state[index2], state[i] index1 = (index1 + 1) % len(b_key) return state def hex_to_byte(in_hex): hexlen = len(in_hex) if hexlen % 2 == 1: hexlen += 1 in_hex = "0" + in_hex result = bytearray.fromhex(in_hex) return result def RC4_base(input, m_key): x = y = xor_index = 0 key = init_key(m_key) result = bytearray(len(input)) for i in range(len(input)): x = (x + 1) & 0xff y = ((key[x] & 0xff) + y) & 0xff key[x], key[y] = key[y], key[x] xor_index = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff result[i] = input[i] ^ key[xor_index] return result def decry_RC4(data, key, charset): if data is None or key is None: return None data_bytes = bytes.fromhex(data) decry_data = RC4_base(data_bytes, key) return decry_data.decode(charset) def main(): data = "需要解密的数据" key = "你的key" charset = "UTF-8" try: decry_data = decry_RC4(data, key, charset) print("Decrypted data: " + decry_data) except Exception as e: print("Decryption failed: " + str(e)) if __name__ == "__main__": main() # Author:QingJ JavaScript: const { TextEncoder, TextDecoder } = require('util'); function main() { const data = "需要解密的数据"; const key = "你的密钥"; const chartSet = "UTF-8"; try { const decryData = decryRC4(data, key, chartSet); console.log(解密后的数据:${decryData}); } catch (e) { console.log(解密失败:${e.message}); } } function decryRC4(data, key, chartSet) { if (!data || !key) { return null; } const decryData = RC4Base(hexToByte(data), key); return new TextDecoder(chartSet).decode(Buffer.from(decryData)); } function initKey(aKey) { const bkey = new TextEncoder().encode(aKey); const state = Buffer.alloc(256); for (const i of state.keys()) { state[i] = i; } let index1 = 0; let index2 = 0; if (bkey.length === 0) { return null; } for (const i of state.keys()) { index2 = ((bkey[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff; [state[i], state[index2]] = [state[index2], state[i]]; index1 = (index1 + 1) % bkey.length; } return state; } function hexToByte(inHex) { const hexlen = inHex.length; let result; if (hexlen % 2 === 1) { hexlen++; result = Buffer.alloc(hexlen / 2); inHex = "0" + inHex; } else { result = Buffer.alloc(hexlen / 2); } let j = 0; for (let i = 0; i < hexlen; i += 2) { result[j++] = parseInt(inHex.substring(i, i + 2), 16); } return result; } function RC4Base(input, mKkey) { let x = 0; let y = 0; const key = initKey(mKkey); let xorIndex; const result = Buffer.alloc(input.length); for (const i of input.keys()) { x = (x + 1) & 0xff; y = ((key[x] & 0xff) + y) & 0xff; [key[x], key[y]] = [key[y], key[x]]; xorIndex = ((key[x] & 0xff) + (key[y] & 0xff)) & 0xff; result[i] = input[i] ^ key[xorIndex]; } return result; } if (require.main === module) { main(); } /** Author:QingJ */ 解密代码来自情不知何起(QingJ),有问题加入后台群700732044请求解决
上一页
获取当前时间戳
下一页
生成签名
Built with