Encryption method for the business version of the business version by Java program registration machine

xiaoxiao2021-04-06  301

A registration machine for a development platform, I spent two weeks, I guess it, what platform I guess, I won't say it! String args = ""; is the original encrypted information, with the company name, I have to remove it.

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 (); byterrayoutputstream = new byterrayoutputstream (); for (k = 0; 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; KeyFa ctory keyfactory = KeyFactory.getInstance ( "RSA"); java.security.PublicKey publickey = keyfactory .generatePublic (x509encodedkeyspec); cipher = Cipher.getInstance ( "RSA", "BC"); cipher.init (2, publickey); i = cipher.getblocksize (); byterrayoutputstream = new byteArrayoutputStream (); for (k = 0; 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 ();

转载请注明原文地址:https://www.9cbs.com/read-132323.html

New Post(0)