Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- * GRAY_GRAY HOLE CODE
- */
- package server1;
- import java.io.*;
- import java.net.*;
- import java.security.Security;
- import javax.crypto.Cipher;
- import de.flexiprovider.core.FlexiCoreProvider;
- import java.security.InvalidKeyException;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.Arrays;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.crypto.BadPaddingException;
- import javax.crypto.IllegalBlockSizeException;
- import javax.crypto.NoSuchPaddingException;
- import javax.crypto.spec.SecretKeySpec;
- import sun.misc.BASE64Encoder;
- public class Server1 {
- private static InetAddress IPAddress;
- private static String Data;
- private static String encryptdecrypt;//
- private static String ALGORITHM;//
- private static String macinfo;
- private static String pass;//
- private static byte[] key;
- //ENCRYPT
- public static String cryp(String cryptData,String pass) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException, BadPaddingException, IllegalBlockSizeException
- {
- Security.addProvider(new FlexiCoreProvider());
- key=UDPData.keydata(pass);
- MessageDigest sha = MessageDigest.getInstance("SHA512");
- key = sha.digest(key);
- key = Arrays.copyOf(key, 16);
- SecretKeySpec secretKey=new SecretKeySpec(key,ALGORITHM);
- Cipher cipher;
- cipher = Cipher.getInstance(ALGORITHM);
- cipher.init(Cipher.ENCRYPT_MODE, secretKey);//secretKey
- byte[] result = cipher.doFinal(cryptData.getBytes());
- String encryptVal;
- encryptVal = new BASE64Encoder().encode(result);
- System.out.println("ENCRYPT:" +encryptVal);
- return encryptVal;
- }
- //DECRYPT
- public static String decryp(String cryptData,String pass) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException, BadPaddingException, IllegalBlockSizeException
- {
- String decript;
- Security.addProvider(new FlexiCoreProvider());
- MessageDigest sha = MessageDigest.getInstance("SHA512");
- key=UDPData.keydata(pass);
- key = sha.digest(key);
- key = Arrays.copyOf(key, 16);
- SecretKeySpec secretKey=new SecretKeySpec(key,ALGORITHM);
- Cipher cipher;
- cipher = Cipher.getInstance(ALGORITHM);
- cipher.init(Cipher.DECRYPT_MODE, secretKey);
- byte[] result = cipher.doFinal(cryptData.getBytes());
- decript = new BASE64Encoder().encode(result);
- System.out.println("DECRYPT:" +decript);
- return decript;
- }
- //FINDSTRINGS NOT SO GOOD
- public static String Findpass(String Datapass) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException, BadPaddingException, IllegalBlockSizeException
- {
- Scanner scan = new Scanner(Datapass);
- String password="password:";
- String username="username:";
- String algoritm="algoritm:";
- String encriptdecript="encriptdecript:";//class objects and others
- System.out.println(scan.findInLine(password));
- password=scan.next();
- System.out.println(scan.findInLine(username));
- username=scan.next();
- System.out.println(scan.findInLine(algoritm));
- ALGORITHM=scan.next();
- scan.findInLine(encriptdecript);
- //encryptdecrypt=scan.next();
- System.out.println(password+username);
- return password+username;
- }
- public static void main(String args[]) throws Exception
- {
- new Thread(new Runnable() {
- @Override
- @SuppressWarnings("empty-statement")
- public void run() {
- try {
- DatagramSocket serverSocket = new DatagramSocket(5556);
- byte[] receiveData = new byte[124];
- byte[] sendData = new byte[124];
- String encryData;
- while(true)
- {
- DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
- serverSocket.receive(receivePacket);
- String sentence = new String(receivePacket.getData());
- pass=Findpass(sentence);
- int port = receivePacket.getPort();
- System.out.println("RECEIVED: "+"ip:"+IPAddress
- +"port:"+port+pass+encryptdecrypt+ALGORITHM);
- IPAddress = InetAddress.getByName("localhost");
- encryData=cryp(sentence,pass);
- sendData=encryData.getBytes();
- System.out.println("SEND: "+"ip:"+IPAddress
- +"port:"+port+encryData);
- DatagramPacket sendPacket =
- new DatagramPacket(sendData, sendData.length, IPAddress, port);
- serverSocket.send(sendPacket);
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (NoSuchAlgorithmException ex) {
- Logger.getLogger(Server1.class.getName()).log(Level.SEVERE, null, ex);
- } catch (NoSuchPaddingException ex) {
- Logger.getLogger(Server1.class.getName()).log(Level.SEVERE, null, ex);
- } catch (InvalidKeyException ex) {
- Logger.getLogger(Server1.class.getName()).log(Level.SEVERE, null, ex);
- } catch (BadPaddingException ex) {
- Logger.getLogger(Server1.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IllegalBlockSizeException ex) {
- Logger.getLogger(Server1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- } ).start();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement