首页 > 编程语言 >【APP逆向10】Java中常见加密与python实现

【APP逆向10】Java中常见加密与python实现

时间:2024-01-23 22:24:34浏览次数:27  
标签:10 java String python APP item print import data

  • 1.隐藏字节,String v4 = new String(new byte[]{-26, -83, -90, -26, -78, -101, -23, -67, -112});
byte_list = [-26, -83, -90, -26, -78, -101, -23, -67, -112]

bs = bytearray()  # python字节数组
for item in byte_list:
    if item < 0:
        item = item + 256
    bs.append(item)

str_data = bs.decode('utf-8')  # data = bytes(bs)
print(str_data)
  • 2.uuid
    • java代码
import java.util.UUID;

public class Hello {
    public static void main(String[] args){
        String uid = UUID.randomUUID().toString();
        System.out.println(uid);
    }
}
  • python实现
import uuid

uid = str(uuid.uuid4())
print(uid)
  • 3.随机值
    • Java实现
import java.math.BigInteger;
import java.security.SecureRandom;

public class Hello {

    public static void main(String[] args) {
        // 随机生成80位,10个字节
        BigInteger v4 = new BigInteger(80, new SecureRandom());
        // 让字节以16进制展示
        String res = v4.toString(16);
        System.out.println(res);

    }
}
  • python实现
import random

data = random.randbytes(10)    #python3.9才有
print([item for item in data])
print([hex(item)[2:] for item in data])
#由于java中少于两位时,会自动补0
print([hex(item)[2:].rjust(2, "0") for item in data])

print("".join([hex(item)[2:].rjust(2, "0") for item in data]))

#如果是python3.9以下版本
import random

byte_list = [random.randint(0, 255) for i in range(10)]
print("".join([hex(item)[2:].rjust(2, "0") for item in byte_list]))
  • 4.MD5加密
    • java实现
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;

public class Hello {

    public static void main(String[] args) throws NoSuchAlgorithmException {
        String name = "周杰伦";
        MessageDigest instance = MessageDigest.getInstance("MD5");
        instance.update("xxxxxx".getBytes());   //加盐
        
        byte[] nameBytes = instance.digest(name.getBytes());
        
        System.out.println(Arrays.toString(nameBytes));

        String res = new String(nameBytes);
        System.out.println(res);

        // 十六进制展示
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<nameBytes.length;i++){
            int val = nameBytes[i] & 255;  // 负数转换为正数
            if (val<16){
                sb.append("0");
            }
            sb.append(Integer.toHexString(val));
        }
        String hexData = sb.toString();
        System.out.println(hexData); // e6ada6e6b29be9bd90
    }
}

  • python实现
import hashlib

obj = hashlib.md5('yyy'.encode('utf-8'))   #加盐
obj.update('xxxxx'.encode('utf-8'))

# java中没有这个功能。
v1 = obj.hexdigest()
print(v1) # fb0e22c79ac75679e9881e6ba183b354

v2 = obj.digest()
print(v2) # b'\xfb\x0e"\xc7\x9a\xc7Vy\xe9\x88\x1ek\xa1\x83\xb3T'
  • 5.AES加密
    java实现
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;

public class Hello {

    public static void main(String[] args) throws Exception {
        String data = "周杰伦";
        String key = "fd6b639dbcff0c2a1b03b389ec763c4b";
        String iv = "77b07a672d57d64c";
		
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        
        // 加密
        byte[] raw = key.getBytes();
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());
        
        
        
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivSpec);
        byte[] encrypted = cipher.doFinal(data.getBytes());
        
        // System.out.println(Arrays.toString(encrypted));
        
    }
}

  • python实现
# pip install pycryptodome
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad

KEY = "fd6b639dbcff0c2a1b03b389ec763c4b"
IV = "77b07a672d57d64c"


def aes_encrypt(data_string):
    aes = AES.new(
        key=KEY.encode('utf-8'),
        mode=AES.MODE_CBC,
        iv=IV.encode('utf-8')
    )
    raw = pad(data_string.encode('utf-8'), 16)
    return aes.encrypt(raw)

data = aes_encrypt("周杰伦")
print(data)
print([ i for i in data])
  • 6.Base64编码
    • java实现
import java.util.Base64;

public class Hello {

    public static void main(String[] args) {
        String name = "周杰伦";
        // 编码
        Base64.Encoder encoder  = Base64.getEncoder();
        String res = encoder.encodeToString(name.getBytes());
        System.out.println(res); // "5q2m5rKb6b2Q"
		
        // 解码
        Base64.Decoder decoder  = Base64.getDecoder();
        byte[] origin = decoder.decode(res);
        String data = new String(origin);
        System.out.println(data); // 周杰伦

    }
}
  • python实现
import base64

name = "周杰伦"

res = base64.b64encode(name.encode('utf-8'))
print(res) # b'5q2m5rKb6b2Q'

data = base64.b64decode(res)
origin = data.decode('utf-8')
print(origin) # "周杰伦"
  • 注意点:base64常与其他加密组合使用,如AES;不同语言特殊符号处理可能不一样,需要我们进行hook后对比再进行相应的替换。

标签:10,java,String,python,APP,item,print,import,data
From: https://www.cnblogs.com/xwltest/p/17983548

相关文章

  • Microsoft 365 开发:开发者如何使用App ID连接Graph API的方法汇总
    51CTOBlog地址:https://blog.51cto.com/u_13969817在上文中我们介绍了如何在AzureAD中注册Application并授权相关GraphAPI,本文将给大家介绍开发者如何使用AppID和Certificate(Secret)通过PowerShell连接GraphAPI?采用AppID和Certificate通过PowerShell连接GraphAPI的命令如下所......
  • 【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Ver
    问题描述AzureComputeGallery可以帮助围绕Azure资源(例如映像和应用程序)生成结构和组织,并且支持全局复制。如果想通过Python代码实现Image-Version从一个AzureComputeGallery复制到另一个中,如何实现呢? 问题解答示例Python代码:importosfrommsrestazure.azure_cloudimpor......
  • Microsoft 365:如何在Azure AD中注册Application并授权相关Graph API
    51CTOBlog地址:https://blog.51cto.com/u_13969817在使用Powershell连接GraphAPI之前,首先管理员要在AzureAD中新建Application,并授权APIPermission和Credentials,本文将给大家做细节介绍:·      在AzureAD中注册Application·      授权GraphAPIPermission· ......
  • 【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Ver
    问题描述AzureComputeGallery可以帮助围绕Azure资源(例如映像和应用程序)生成结构和组织,并且支持全局复制。如果想通过Python代码实现Image-Version从一个AzureComputeGallery复制到另一个中,如何实现呢? 问题解答示例Python代码:importosfrommsrestazure.azure_cl......
  • 每日总结(python文本分析)
    导入文本文档并输出在终端#Python3.x版本importos#获取根目录下文件的绝对路径root_path="./"file_path=os.path.join(root_path,'pinglun.txt')try:#打开文本文件并读取所有内容withopen(file_path,'r',encoding='utf-8')asfile:......
  • 假期学习记录10
    本次学习学习了RDD的编程概述RDD创建1、从文件系统中加载数据创建RDDSpark采用textFile()方法来从文件系统中加载数据创建RDD该方法把文件的URI作为参数,这个URI可以是:本地文件系统的地址或者是分布式文件系统HDFS的地址或者是AmazonS3的地址等等本地进行加载scala>val......
  • 看起不起眼,却能一天加100人的引流方法
    如果正在创业的你因为缺客源而导致生意停滞不前那么接下来,我分享的你要认真听了,这五种引流方法一定能帮到你。——❶截流法就是去别的博主下面截取他的流量,从而将他的粉丝吸引到你的私域。这个方法看似不起眼,做的人却很多不仅能吸引大量人群,还很精-准。比如你吸引创业粉,就去搜索创......
  • 一种快速开发适配鸿蒙的App思路:基于小程序技术
    今年,在中国,被各大媒体和开发者称为“鸿蒙元年”。 在2023年底就有业内人士透露,华为明年将推出不兼容安卓的鸿蒙版本,未来IOS、鸿蒙、安卓将成为三个各自独立的系统。 果不其然,执行力超强的华为,与2024年1月18日的开发者(HDC)大会上,就官宣了“纯血鸿蒙”操作系统即将于2024......
  • 搭建互联网医疗平台:构建智慧医院APP的开发指南
    本文将从技术层面出发,为大家提供构建互联网医疗平台、打造智慧医院APP的详细开发指南。 一、确定需求与功能在开始开发之前,首先需要明确智慧医院APP的需求与功能。这包括患者预约挂号、在线咨询、病历查看、医疗报告查询等功能。二、选择合适的开发框架与技术选择合适的开发框架对......
  • 问题:10、为了保证通信的可靠性,按照国际标准,AIS应______频道收发AIS信息。
    问题:10、为了保证通信的可靠性,按照国际标准,AIS应______频道收发AIS信息。A.使用87BB.使用88BC.交替使用87B和88BD.同时使用87B和88B参考答案如图所示......