# Xcode Decryption Guide

# Introduction

This guide offers simple, ready-to-use examples for decrypting xcode using AES-256-CBC in various programming languages. It also includes the commands to install any required packages, making it quick and easy to get started.

# NodeJS

No additional packages are required for the xcode decryption in NodeJS, as we're using the built-in crypto module.

JS
const crypto = require("crypto");

function decryptXcode(xcode, secretKey) {
  const [ivHex, encryptedData] = xcode.split(":");
  const iv = Buffer.from(ivHex, "hex");
  const key = crypto.createHash("sha256").update(secretKey).digest();

  const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
  let decrypted = decipher.update(encryptedData, "hex", "utf8");
  decrypted += decipher.final("utf8");

  return decrypted.trim();
}

# Python

For Python, you'll need to install the cryptography package. You can do this using pip:

Bash
pip install cryptography
Python
import hashlib
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend

def decrypt_xcode(xcode, secret_key):
    iv_hex, encrypted_data = xcode.split(':')
    iv = bytes.fromhex(iv_hex)
    key = hashlib.sha256(secret_key.encode()).digest()

    cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
    decryptor = cipher.decryptor()

    decrypted_data = decryptor.update(bytes.fromhex(encrypted_data)) + decryptor.finalize()
    return decrypted_data.decode('utf-8').strip()

# PHP

No additional packages are required for PHP, as we're using built-in functions.

PHP
function decryptXcode($xcode, $secretKey) {
    list($ivHex, $encryptedData) = explode(':', $xcode, 2);
    $iv = hex2bin($ivHex);
    $key = hash('sha256', $secretKey, true);

    $decrypted = openssl_decrypt(
        hex2bin($encryptedData),
        'AES-256-CBC',
        $key,
        OPENSSL_RAW_DATA,
        $iv
    );

    return trim($decrypted);
}

# Go

No additional packages are required for Go, as we're using the standard library.

Go
import (
    "crypto/aes"
    "crypto/cipher"
    "crypto/sha256"
    "encoding/hex"
    "strings"
)

func decryptXcode(xcode, secretKey string) (string, error) {
    parts := strings.SplitN(xcode, ":", 2)
    if len(parts) != 2 {
        return "", fmt.Errorf("invalid xcode format")
    }

    ivHex, encryptedDataHex := parts[0], parts[1]
    iv, err := hex.DecodeString(ivHex)
    if err != nil {
        return "", err
    }

    encryptedData, err := hex.DecodeString(encryptedDataHex)
    if err != nil {
        return "", err
    }

    key := sha256.Sum256([]byte(secretKey))
    block, err := aes.NewCipher(key[:])
    if err != nil {
        return "", err
    }

    mode := cipher.NewCBCDecrypter(block, iv)
    mode.CryptBlocks(encryptedData, encryptedData)

    return strings.TrimSpace(string(encryptedData)), nil
}

# .NET (C#)

No additional packages are required for .NET, as we're using the built-in System.Security.Cryptography namespace.

C#
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

public static string DecryptXcode(string xcode, string secretKey)
{
    string[] parts = xcode.Split(':');
    if (parts.Length != 2)
        throw new ArgumentException("Invalid xcode format");

    byte[] iv = HexStringToByteArray(parts[0]);
    byte[] encryptedData = HexStringToByteArray(parts[1]);

    using (var sha256 = SHA256.Create())
    {
        byte[] key = sha256.ComputeHash(Encoding.UTF8.GetBytes(secretKey));

        using (var aes = Aes.Create())
        {
            aes.Key = key;
            aes.IV = iv;
            aes.Mode = CipherMode.CBC;

            using (var decryptor = aes.CreateDecryptor())
            using (var ms = new MemoryStream(encryptedData))
            using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
            using (var sr = new StreamReader(cs))
            {
                return sr.ReadToEnd().Trim();
            }
        }
    }
}

private static byte[] HexStringToByteArray(string hex)
{
    int NumberChars = hex.Length;
    byte[] bytes = new byte[NumberChars / 2];
    for (int i = 0; i < NumberChars; i += 2)
        bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
    return bytes;
}

# Ruby

No additional gems are required for Ruby, as we're using the built-in openssl library.

Ruby
require 'openssl'

def decrypt_xcode(xcode, secret_key)
  iv_hex, encrypted_data_hex = xcode.split(':')
  iv = [iv_hex].pack('H*')
  encrypted_data = [encrypted_data_hex].pack('H*')

  key = Digest::SHA256.digest(secret_key)

  decipher = OpenSSL::Cipher.new('AES-256-CBC')
  decipher.decrypt
  decipher.key = key
  decipher.iv = iv

  decrypted = decipher.update(encrypted_data) + decipher.final
  decrypted.strip
end