Wednesday, March 16, 2016

CODE SIGNING FOR EXE AND JARS


Code signing



Code signing is the process of digitally signing executables  such as exe ,dll and scripts to confirm the software security.
-If Exe is signed ,It wont show warning during downloading from Internet 
  and also it is applicable to jars and applets  also.


- Some CAs provider

1.Comodo
2.Symantec
3.GoDaddy
4.GlobalSign,
5.DigiCert
6.StartCom,
7.Entrust
8.Verizon,
9.Trustwave
10.Secom
11.Unizeto
12.QuoVadis
13.Deutsche 
14.Telekom
15.Network Solutions
16.SwissSign

They provide certificates with some license period.
-Before Buying certificates,
For verification..
u can try it at your local system by self signed certificates.



Use this commands in command prompt by running as a administrator.
EXE SIGNER: 
TOOL:-
 signtool

STEPS:


1. SET PATH TO MICROSOFT SDKS:-

  set path= C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin"

2. MAKING SELF SIGNED CERTIFICATES:-

  makecert -r -pe -ss MyCertStore -n "CN=MyTestCert" MyTestCert.cer


(NOTE:

Import this certificate to Trusted certificate part in certmgr.msc in windows.

Then only It won’t show unknown publisher at local system.

TO VERIFY:

In windows ,Just type certmgr.msc in start window search box, certmgr.msc will prompt on screen ,
open that and then check whether certificate is successfully imported in Trusted certificate part.)


3. SIGN IN EXE USING SIGNTOOL

   signtool sign /s MyCertStore /n MyTestCert  sample.exe

4. TO VERIFY EXE IS SIGNED OR NOT
  
   
   SignTool verify /pa sample.exe


EXE SIGNER FOR JAR WRAPPED INSIDE A EXE USING LAUNCH4J:


1. CERTIFICATION CREATION IS SAME AS NORMAL EXE SIGNER.

  makecert -r -pe -ss MyCertStore -n "CN=MyTestCert" MyTestCert.cer


2. SIGN IN EXE USING SIGNTOOL AND SIGN4J:
   
  sign4j signtool sign /s MyCertStore /n MyTestCert  "sample.exe"


JAR SIGNER:


SET PATH TO JDK BIN AND THEN PROCEED

1.GENERATION OF CERTIFICATE USING KEYTOOL:-

   keytool -keystore clientkeystore -genkey -alias client

   //GIVE NECCESARY INFORMATION AS TOOL PROMPTS

   keytool -keystore clientkeystore -certreq -alias client -keyalg rsa -file client.csr

   //TYPE KEYSTORE PASSWORD AND KEY PASSOWRD AS IT PROMPTS


2.SIGN IN JAR USING JAR SIGNER:-

jarsigner -keystore clientkeystore -storepass client@123 -keypass key@123   sample.jar client

IF SECURITY EXCEPTION OCCURS TRY FOLLOWING COMMAND:

jarsigner -keystore clientkeystore -digestalg SHA1 Lektz.jar client

3.TO CHECK WHEATHER JAR IS VERIFIED OR NOT:

jarsigner -verify samplejar

FOR DETAILED INFORMATION:

jarsigner -verify -verbose -certs example.jar


ORACLE DOCUMENT REFERENCE FOR JAR SIGNER:




Sunday, March 6, 2016

WEB VIEW WITH TOGGLE RADIO BUTTON GROUP IN JAVAFX


WEB VIEW WITH TOGGLE RADIO BUTTON GROUP IN JAVAFX

 

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;


public class webChooser extends Application
{
   

    @Override
    public void start(final Stage stage) throws Exception
    {
        BorderPane bp=new BorderPane();
        HBox hb1=new HBox();
        HBox hb2=new HBox();
        HBox hb3=new HBox();
        //hb.setSpacing(10);
        hb1.setPadding(new Insets(10,10,10,10));
        hb2.setPadding(new Insets(10,10,10,10));
        hb3.setPadding(new Insets(10,10,10,10));
        final ToggleGroup group = new ToggleGroup();
        RadioButton rb1 = new RadioButton("");
        //rb1.setMaxSize(maxWidth, maxHeight);
        rb1.setStyle("-fx-background-color: #FFFFFF;");
        rb1.setMaxSize(400, 100);
        rb1.setToggleGroup(group);
        RadioButton rb2 = new RadioButton("");
        //rb1.setMaxSize(maxWidth, maxHeight);
        rb2.setStyle("-fx-background-color: #FFFFFF;");
        rb2.setMaxSize(400, 100);
        rb2.setToggleGroup(group);
        RadioButton rb3 = new RadioButton("");
        //rb1.setMaxSize(maxWidth, maxHeight);
        rb3.setStyle("-fx-background-color: #FFFFFF;");
        rb3.setMaxSize(400, 100);
         rb3.setToggleGroup(group);
        //rb1.setSelected(true);
        //web view 1
        final WebView browser = new WebView();
        browser.setMaxSize(400, 100);
        webEngine(browser, stage);
         hb1.getChildren().addAll(browser,rb1);
        //web view 2
        final WebView browser2 = new WebView();
        browser2.setMaxSize(400, 100);
        webEngine(browser2, stage);
         hb2.getChildren().addAll(browser2,rb2);
        //web view 3
        final WebView browser3 = new WebView();
        browser3.setMaxSize(400, 100);
        webEngine(browser3, stage);
         hb3.getChildren().addAll(browser3,rb3);
        //browser.setLayoutY(100);
        VBox vb=new VBox();
        vb.getChildren().addAll(hb1,hb2,hb3);
        Scene sc=new Scene(vb);
        stage.setScene(sc);
        stage.show();   
    }
    public void webEngine(WebView browser,final Stage stage)
    {
        final WebEngine webEngine = browser.getEngine();
        webEngine.getLoadWorker().stateProperty()
            .addListener(new ChangeListener<State>() {
              public void changed(ObservableValue ov, State oldState, State newState) {

                if (newState == Worker.State.SUCCEEDED) {
                  stage.setTitle(webEngine.getLocation());
                }

              }
            });
        webEngine.load("file:///C:/Users/use/Desktop/web.html");
       
    }
    public static void main(String args[])
    {
        launch(args);
    }
   
   

}
 

REGISTRATION FORM DESIGN WITH DESIGN STYLES IN JAVAFX


REGISTRATION FORM DESIGN  WITH DESIGN STYLES IN JAVAFX


import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;


public class signup extends Application
{

    @Override
    public void start(Stage arg0) throws Exception
    {
   
       
        BorderPane bp=new BorderPane();
        bp.setPadding(new Insets(50,50,50,50));
        HBox hbtit=new HBox();
        hbtit.setPadding(new Insets(30,30,30,30));
        hbtit.setSpacing(50);
        Image image = new Image("signup.png");
        ImageView iv1 = new ImageView();
        iv1.setImage(image);
        //HBOX TOP
        HBox hb=new HBox();
        hb.setPadding(new Insets(50,50,50,50));
        hb.setSpacing(50);
        hb.getChildren().addAll(hbtit);
        hb.setStyle("-fx-background-color: #3FF4CB;");
        bp.setTop(hb);
        //HBOX BOTTOM
        HBox hdb=new HBox();
        hdb.setPadding(new Insets(50,50,50,50));
        hdb.setSpacing(50);
        hdb.setStyle("-fx-background-color: #3FF4CB;");
        bp.setBottom(hdb);
        //VBOX LEFT
        VBox vdl=new VBox();
        vdl.setPadding(new Insets(50,50,50,50));
        vdl.setSpacing(50);
        vdl.setStyle("-fx-background-color: #3FF4CB;");
        bp.setLeft(vdl);
        //VBOX RIGHT
        VBox vdr=new VBox();
        vdr.setPadding(new Insets(50,50,50,50));
        vdr.setSpacing(50);
        vdr.setStyle("-fx-background-color: #3FF4CB;");
        bp.setRight(vdr);
       
        //CENTER GRID
        //GridPane gd=new GridPane();
        //gd.add(child, columnIndex, rowIndex);
        GridPane gdtop=new GridPane();
        gdtop.setPadding(new Insets(60,60,60,60));
        gdtop.setVgap(30);
        gdtop.setHgap(40);
       
        GridPane.setHalignment(iv1, HPos.CENTER);
        gdtop.add(iv1, 0, 0);
        Label title=new Label("SIGN UP");
        title.setFont(Font.font("Arial",FontWeight.BOLD, 40));
         GridPane.setHalignment(title, HPos.CENTER);
         gdtop.add(title, 1, 0);
         //NAME LABEL
         Label name=new Label("NAME");
         name.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         gdtop.add(name, 0, 1);
         //NAME TEXT BOX
         TextField namet=new TextField();
         namet.setPromptText("Name");
         gdtop.add(namet, 1, 1);
        //EMAIL ADDRESS LABEL
         Label email=new Label("EMAIL ID");
         email.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         gdtop.add(email, 0, 2);
         //EMAIL TEXT BOX
         TextField emailt=new TextField();
         emailt.setPromptText("Email Address");
         gdtop.add(emailt, 1, 2);
         //CONFIRM EMAIL ADDRESS LABEL
         Label cemail=new Label("CONFIRM EMAIL");
         cemail.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         gdtop.add(cemail, 0, 3);
         //CONFIRM EMAIL ADDRESS TEXT BOX
         TextField emailct=new TextField();
         emailct.setPromptText("Confirm Email Address");
         gdtop.add(emailct, 1, 3);
         //MOBILE NUMBER LABEL
         Label mobnol=new Label("MOBILE NUMBER");
         mobnol.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         gdtop.add(mobnol, 0, 4);
         //MOBILE NUMBER TEXT FIELD
         TextField mobnot=new TextField();
         mobnot.setPromptText("Phone/Mobile No");
         gdtop.add(mobnot, 1, 4);
         //PASSWORD LABEL
         Label pwd=new Label("PASSWORD");
         pwd.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         gdtop.add(pwd, 0, 5);
         //PASSWORD TEXTFIELD
         TextField pwdt=new TextField();
         pwdt.setPromptText("Password");
         gdtop.add(pwdt, 1, 5);
         //CONFIRM PASSWORD LABEL
         Label cpwd=new Label("CONFIRM PASSWORD..");
         cpwd.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         gdtop.add(cpwd, 0, 6);
         //CONFIRM PASSWORD TEXTFIELD
         TextField pwdc=new TextField();
         pwdc.setPromptText("Confirm Password");
         gdtop.add(pwdc, 1, 6);
         //SUBMIT BUTTON HBOX
         HBox subh=new HBox();
        // subh.setPadding(new Insets(50,50,50,50));
        // subh.setSpacing(20);
         subh.setAlignment(Pos.CENTER_RIGHT);
       
         //SUBMIT BUTTON
         HBox canch=new HBox();
       
        // canch.setPadding(new Insets(10,10,10,10));
         //canch.setSpacing(20);
         canch.setAlignment(Pos.CENTER_LEFT);
         Button submit=new Button("Submit");
         submit.setCursor(Cursor.HAND);
         submit.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         submit.setStyle("-fx-background-color: #3FF4CB;");
        // GridPane.setHalignment(submit, HPos.CENTER);
         subh.getChildren().addAll(submit);
         gdtop.add(subh, 0, 7);
         //CANCEL BUTTON
         Button cancel=new Button("Cancel");
         cancel.setCursor(Cursor.HAND);
         cancel.setFont(Font.font("Arial",FontWeight.BOLD, 20));
         cancel.setStyle("-fx-background-color: #3FF4CB;");
         canch.getChildren().addAll(cancel);
        // GridPane.setHalignment(cancel, HPos.CENTER);
         gdtop.add(canch,1,7);
         bp.setCenter(gdtop);
         Scene scene =new Scene(bp);
        arg0.setTitle("ACCOUNT SIGN UP");
        arg0.setScene(scene);
        arg0.show();
       
       
    }
    public static void main(String[] args)
    {
        launch(args);
       
    }

}

PASSING AND RETRIVING IMAGE IN JSON USING JAVAFX


PASSING AND RETRIVING IMAGE IN JSON USING JAVAFX 


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import javax.swing.JOptionPane;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

public class ImageChooser extends Application
{
    private List<File> list;
    private String imgpath;
    private HBox hb;
    private BorderPane bn;
    private Stage stagenew;
    private Button b1;
    private static String imgname;


    @Override
    public void start(Stage paramStage) throws Exception {
   
        stagenew=paramStage;
        imgpath="D:\\Ragava\\ragava\\workspace\\Sample\\src\\defimage.jpg";
       
        //BUTTON EVENT TO TRIGGER ACTION
         b1=new Button("IMAGE FILE CHOOSER");
         b1.setOnAction(new EventHandler() {
             public void handle(Event arg0)
             {
                // TODO Auto-generated method stub
                addMultipleBooks();
                 try {             
                     String imageDataString=ImageToString();
                     StrTOJson(imageDataString);
                     String imgdata=ReadJson();
                    
                      DecodeProcesss(imgdata);
                      GenerateScene();
                      JOptionPane.showMessageDialog(null,"IMAGE SUCCESSFULLY UPLODED TO JSON...");
                   
         
                     System.out.println("Image Successfully Manipulated!");
                 } catch (FileNotFoundException e) {
                     System.out.println("Image not found" + e);
                 } catch (IOException ioe) {
                     System.out.println("Exception while reading the Image " + ioe);
                 } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
               
               
               
               
            }
            
             });
       
       
     
        GenerateScene();   
       
    }
    //JAVAFX SCENCE CREATION
    public void GenerateScene()
    {
        bn=new BorderPane();
        bn.setBottom(b1);
        hb=new HBox();
   
         ImageView iv1=ImageSetup();
            System.out.println("FINISHED..");  
            hb.getChildren().addAll(iv1);
            System.out.println("hbox addedd.."); 
            bn.setCenter(hb);
            System.out.println("centered.."); 
            Scene sc=new Scene(bn);
            stagenew.setScene(sc);
            stagenew.show();   
    }
    private ImageView ImageSetup()
    {
       
        System.out.println("ENTERED..");
           File file = new File(imgpath);
            Image image = new Image(file.toURI().toString());
            ImageView iv1 = new ImageView();
            iv1.setImage(image);
            return iv1;
       
           
       
    }
    private void addMultipleBooks()
    {

        FileChooser fileChooser = new FileChooser();
        configureFileChooser(fileChooser);
       
   
        list = fileChooser.showOpenMultipleDialog(null);
        imgpath=list.get(0).getAbsolutePath();
        System.out.println(imgpath);
        JOptionPane.showMessageDialog(null,imgpath);
       
       
    }
        private static void configureFileChooser(final FileChooser fileChooser) {
            fileChooser.setTitle("View Pictures");
            fileChooser.setInitialDirectory(new File(System
                    .getProperty("user.home")));
            fileChooser.getExtensionFilters().addAll(
                    new FileChooser.ExtensionFilter("Files", "*.jpg", "*.png"),
                    new FileChooser.ExtensionFilter("JPG", "*.jpg"),
                    new FileChooser.ExtensionFilter("PNG", "*.png"));
        }
        // READING JSON FILE
        public static String ReadJson()
        {
           
             String imagbin="";
                String srcUrl = "D://imgeparser.json";
                String line;
                String jsondata="";
                StringBuffer stringBuffer = new StringBuffer();
                JSONObject jsonObj=null,jsonOut=null;
                try {

                    File file = new File(srcUrl);
                    if (file.exists()) {

                        FileReader fileReader = new FileReader(file);
                        BufferedReader bufferedReader = new BufferedReader(fileReader);

                        while ((line = bufferedReader.readLine()) != null) {
                            stringBuffer.append(line);
                            stringBuffer.append("\n");
                        }
                        fileReader.close();
                        jsondata=stringBuffer.toString();
                    }
                       
                    jsonObj = new JSONObject(jsondata);
                        String status = jsonObj.getString("Result");
                        System.out.println("JSON RESPONSE.."+status);
                        if (status.equals("success"))
                        {
                           
                             imagbin=jsonObj.getString("image-bin");
                             System.out.println("image binary.."+imagbin);
                             String imgname=jsonObj.getString("imagename");
                             System.out.println("image name.."+imgname);
                             System.out.println("READED SUCCESSFULLY..");
                            
                           

                        }
                        else
                        {
                            System.out.println("ERROR IN RATE..");
                        }
                   
                    
                   
        }          catch (Exception e) {
                        e.printStackTrace();
                    }

                 return imagbin;     
           
        }
        //CREATING JSON FILE
        public static void StrTOJson(String imagetxt) throws JSONException
        {
           
            JSONObject obj = new JSONObject();
           
            obj.put("imagename",imgname);
            obj.put("image-bin", imagetxt);   
            obj.put("Result","success");
            try {
               
                FileWriter file = new FileWriter("D://imgeparser.json");
                file.write(obj.toString());
                System.out.println("Successfully Copied JSON Object to File...");
                System.out.println("\nJSON Object: " + obj);
                file.close();
            }
            catch(Exception ex)
            {
                System.out.println("ERROR.."+ex.getMessage());
            }
           
        }
       
        //CONVERTING IMAGE TO STRING USING ENCODING AND DECODING PROCESS
        public  String ImageToString() throws IOException
        {
            //File file = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Tulips.jpg");
            File file = new File(imgpath);
            imgname=file.getName();
            FileInputStream imageInFile = new FileInputStream(file);
            byte imageData[] = new byte[(int) file.length()];
            imageInFile.read(imageData);
            imageInFile.close();
            String imageDataString = encodeImage(imageData);
            System.out.println("Image String.."+imageDataString);
            return imageDataString; 
           
        }
       
        //DECODING IMAGE
        public void DecodeProcesss(String imageDataString) throws IOException
        {
             byte[] imageByteArray = decodeImage(imageDataString);
             FileOutputStream imageOutFile = new FileOutputStream(
                     "D:\\JSON IMAGE\\"+imgname);

             imageOutFile.write(imageByteArray);
             // Converting a Base64 String into Image byte array
          
             imageOutFile.close();
           
        }
       
   
        //ENCODE IMAGE
        public static String encodeImage(byte[] imageByteArray) {
            return Base64.encodeBase64URLSafeString(imageByteArray);
        }
   
        //DECODE IMAGE
        public static byte[] decodeImage(String imageDataString) {
            return Base64.decodeBase64(imageDataString);
        }

        public static void main(String[] args)
        {
            launch(args);
        }
   

}

CREATING AND READING JSON FILE

CREATING JSON FILE


        public static void StrTOJson(String imagetxt) throws JSONException
        {
           
            JSONObject obj = new JSONObject();
           
            obj.put("imagename",imgname);
            obj.put("image-bin", imagetxt);   
            obj.put("Result","success");
            try {
               
                FileWriter file = new FileWriter("D://imgeparser.json");
                file.write(obj.toString());
                System.out.println("Successfully Copied JSON Object to File...");
                System.out.println("\nJSON Object: " + obj);
                file.close();
            }
            catch(Exception ex)
            {
                System.out.println("ERROR.."+ex.getMessage());
            }
           
        }



READING JSON FILE:

 

        public static String ReadJson()
        {
          
             String imagbin="";
                String srcUrl = "D://imgeparser.json";
                String line;
                String jsondata="";
                StringBuffer stringBuffer = new StringBuffer();
                JSONObject jsonObj=null,jsonOut=null;
                try {

                    File file = new File(srcUrl);
                    if (file.exists()) {

                        FileReader fileReader = new FileReader(file);
                        BufferedReader bufferedReader = new BufferedReader(fileReader);

                        while ((line = bufferedReader.readLine()) != null) {
                            stringBuffer.append(line);
                            stringBuffer.append("\n");
                        }
                        fileReader.close();
                        jsondata=stringBuffer.toString();
                    }
                      
                    jsonObj = new JSONObject(jsondata);
                        String status = jsonObj.getString("Result");
                        System.out.println("JSON RESPONSE.."+status);
                        if (status.equals("success"))
                        {
                          
                             imagbin=jsonObj.getString("image-bin");
                             System.out.println("image binary.."+imagbin);
                             String imgname=jsonObj.getString("imagename");
                             System.out.println("image name.."+imgname);
                             System.out.println("READED SUCCESSFULLY..");
                           
                          

                        }
                        else
                        {
                            System.out.println("ERROR IN RATE..");
                        }
                  
                   
                  
        }          catch (Exception e) {
                        e.printStackTrace();
                    }

                 return imagbin;    
          
        }