由Java程序注册机联想到商业版程序的加密方法

转载 2006年06月22日 16:20:00

某开发平台的注册机,花了我两个星期的时间才搞定,是什么平台自己去猜,我就不说了! String args = "";是原来的加密信息,有公司名称,只好取掉了。

import java.io.ByteArrayOutputStream;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.Security;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class rsaok {
 private byte[] PrivateKey;

 private byte[] PublicKey;

 public static void main(String[] args) {
  BouncyCastleProvider bouncycastleprovider = new BouncyCastleProvider();
  if (Security.getProperty(bouncycastleprovider.getName()) == null)
   Security.addProvider(bouncycastleprovider);
  rsaok t = new rsaok();
  t.key();
  t.encrypt();
 }

 public void encrypt() {
  String args = "";
  byte abyte0[] = null;
  Cipher cipher;
  byte abyte1[];
  int i;
  ByteArrayOutputStream bytearrayoutputstream;
  int k;
  try {
   PKCS8EncodedKeySpec pkcs8encodedkeyspec = new PKCS8EncodedKeySpec(
     PrivateKey);
   KeyFactory keyfactory = KeyFactory.getInstance("RSA");
   java.security.PrivateKey privatekey = keyfactory
     .generatePrivate(pkcs8encodedkeyspec);
   cipher = Cipher.getInstance("RSA", "BC");
   cipher.init(2, privatekey);
   abyte1 = args.getBytes();
   i = cipher.getBlockSize();
   bytearrayoutputstream = new ByteArrayOutputStream();
   for (k = 0; k < abyte1.length;) {
    int j;
    if (abyte1.length - k >= i)
     j = i;
    else
     j = abyte1.length - k;
    bytearrayoutputstream.write(cipher.doFinal(abyte1, k, j));
    k += i;
   }
   bytearrayoutputstream.flush();
   bytearrayoutputstream.close();
   abyte0 = bytearrayoutputstream.toByteArray();
   System.out.println(byte2hex(abyte0));
   decrypt(abyte0);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

 public void decrypt(byte[] abyte1) {
  try {
   String a = "323856EEAD0A7415283B7B58BDCDD6F58A0EB672E9A134C4923D1230D5E2F6B87CD2FAE30E2DB6CB50C60E3C7E91DD9D41938D63B28A0D6BE380EBFA748C99E81A4F983343D80C1541728B1259F49FDB4DCCAA62563AC3C14A91B6C7C374E7AE6B508D79487442B99390AF7C5A699A7040FB6FA7E9EF511003836C646ED45651";
   X509EncodedKeySpec x509encodedkeyspec = new X509EncodedKeySpec(PublicKey);
   //X509EncodedKeySpec x509encodedkeyspec = new X509EncodedKeySpec(hex2byte("30819F300D06092A864886F70D010101050003818D0030818902818100BE0C59D90E7A5A582626A209492452475130557AAE4400180BCB5B0E4138F8C8DED8185E51D17A5FF8B873084742CC245C6DC636432CBAA5401E5312EBA05A4AB79CB71C71A0E0221BB39DA9893026110447F9820B48C88B8A9862ABADB3E5462FADD45E3DD251658F48124C6AA091831404E52471A72A4D6CC989EA4959DECB0203010001"));
   Cipher cipher;
   int i;
   ByteArrayOutputStream bytearrayoutputstream;
   int k;
   KeyFactory keyfactory = KeyFactory.getInstance("RSA");
   java.security.PublicKey publickey = keyfactory
     .generatePublic(x509encodedkeyspec);
   cipher = Cipher.getInstance("RSA", "BC");
   cipher.init(2, publickey);
   i = cipher.getBlockSize();
   bytearrayoutputstream = new ByteArrayOutputStream();
   for (k = 0; k < abyte1.length;) {
    int j;
    if (abyte1.length - k >= i)
     j = i;
    else
     j = abyte1.length - k;
    bytearrayoutputstream.write(cipher.doFinal(abyte1, k, j));
    k += i;
   }
   byte abyte0[];
   bytearrayoutputstream.flush();
   bytearrayoutputstream.close();
   abyte0 = bytearrayoutputstream.toByteArray();
   System.out.println(new String(abyte0));
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

 public void key() {
  try {
   KeyPairGenerator kpg = null;
   kpg = KeyPairGenerator.getInstance("RSA", "BC");
   kpg.initialize(1024);
   KeyPair kp = kpg.generateKeyPair();
   PrivateKey = kp.getPrivate().getEncoded();
   System.out.println("PrivateKey:"+byte2hex(PrivateKey));
   PublicKey = kp.getPublic().getEncoded();
   System.out.println("PublicKey:"+byte2hex(PublicKey));
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

 private String byte2hex(byte[] b) {
  String hs = "";
  String stmp = "";
  for (int n = 0; n < b.length; n++) {
   stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
   if (stmp.length() == 1)
    hs = hs + "0" + stmp;
   else
    hs = hs + stmp;
   if (n < b.length - 1)
    hs = hs + ":";
  }
  return hs.toUpperCase();
 }

 public byte[] hex2byte(String hex) throws IllegalArgumentException {
  if (hex.length() % 2 != 0) {
   throw new IllegalArgumentException();
  }
  char[] arr = hex.toCharArray();
  byte[] b = new byte[hex.length() / 2];
  for (int i = 0, j = 0, l = hex.length(); i < l; i++, j++) {
   String swap = "" + arr[i++] + arr[i];
   int byteint = Integer.parseInt(swap, 16) & 0xFF;
   b[j] = new Integer(byteint).byteValue();
  }
  return b;
 }
}

相关文章推荐

江湖家居V4.1最新多城市商业版, PHP家居装修装饰系统V4.1,含5套VIP模板+注册机!by - 捡肥皂

江湖家居V4.1最新多城市商业版, PHP家居装修装饰系统V4.1,含5套VIP模板+注册机! 演示地址:(以截图为准) http://hefei.ijianghu.net/ ...

微赞WZ_V51.2版本20160706UTF8商业版程序同步完整包 带400多功能模

微赞程序的介绍: 微赞WZ微信公众平台开源程序-是微动力程序的衍生强化版,实现多微站,多客户转接,多功能群发,粉丝会员积分统一,模块嫁接等功能,具有高度的安全特性!100%开源,程序可自由控制!便于...

百威9000V6商业版注册机

  • 2012-02-13 19:13
  • 3.50MB
  • 下载

Android逆向实例笔记—记一第一次为Android程序写注册机(短信轰炸机)

短信轰炸机的app简单的分析和注册机的编写

泰格至尊版软件加密锁注册机

特别提醒:经典版仅供学习,不可用于商业用途,否则后果自负。该系统属于机密系统,因使用该系统引起的任何结果,后果自负,与共享者无关。该系统不属于破解版,是内部人士透露出的正式注册系统。
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)