bugku easy-100 完整代码

bugku easy-100

代码有点乱,但是比较完整。

package t1;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;

public class main {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	System.out.println("Hello World dd");

	//ma p() return this_is_the_key.
    File file = new File("/Users/liben/Desktop/url.png");
	String v = "";
    try {
        InputStream v0_1 = new FileInputStream(file);
        int v1 = v0_1.available();
        byte[] v2 = new byte[v1];
        v0_1.read(v2, 0, v1);
        byte[] v0_2 = new byte[16];
        System.arraycopy(v2, 0x90, v0_2, 0, 16);
        v = new String(v0_2, "utf-8");
    }
    catch(Exception v0) {
        v0.printStackTrace();
    }
    System.out.println(v);
    
    
    //c a() this_is_the_key. input
    //c a() this_is_the_key. => htsii__sht_eek.y
    String v0_2;
    try {
        v.getBytes("utf-8");
        StringBuilder v1 = new StringBuilder();
        int v0_1;
        for(v0_1 = 0; v0_1 < v.length(); v0_1 += 2) {
            v1.append(v.charAt(v0_1 + 1));
            v1.append(v.charAt(v0_1));
        }

        v0_2 = v1.toString();
    }
    catch(UnsupportedEncodingException v0) {
        v0.printStackTrace();
        v0_2 = null;
    }
    System.out.println(v0_2);
	
    //a a() htsii__sht_eek.y
    byte[] arg4 = v0_2.getBytes();
    SecretKeySpec a = null;
    Cipher b = null;
    try {
        a = new SecretKeySpec(arg4, "AES");
        b = Cipher.getInstance("AES/ECB/PKCS5Padding");
    }
    catch(NoSuchAlgorithmException vv0_1) {
        vv0_1.printStackTrace();
    }
    catch(NoSuchPaddingException vv0_2) {
        vv0_2.printStackTrace();
    }
    
    try {
		b.init(1, a);
	} catch (InvalidKeyException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    
    String inp = "xxxx";
    String vv = null;
    try {
        vv = new String(b.doFinal(inp.getBytes()), "utf-8");
    }
    catch(Exception vvv0_1) {
        vvv0_1.printStackTrace();
    }
    System.out.println(vv);
    
    
    
    byte[] bb = new byte[]{21, -93, -68, -94, 86, 0x75, -19, -68, -92, 33, 50, 0x76, 16, 13, 1, -15, -13, 3, 4, 103, -18, 81, 30, 68, 54, -93, 44, -23, 93, 98, 5, 59};
    String strHexBytes = DatatypeConverter.printHexBinary(bb);
    System.out.println(strHexBytes);
    
    byte[] decrypt;
	try {
		decrypt = decrypt(bb, v0_2);
		System.out.println("解密后的内容:" + new String(decrypt,"utf-8"));
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    
    
}



public static byte[] decrypt(byte[] content, String password) throws UnsupportedEncodingException {
    try {
        byte[] raw = password.getBytes("utf-8");
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        byte[] original = cipher.doFinal(content);
        return original;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    }
    return null;
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值