Sunday, August 3, 2014
In an earlier post here , we have shown you how to sign data and generate a digital signature in Java. Generating the signature alone does not provide security, you will also have to verify the digital signature. So according to that today I am going to show you how to verify a Digital Signature in Java. Here in our example we will show how you can do it once you are provided with the original dta, the public key (whose corresponding private key was used to sign the data) and finally the signature bytes that were generated earlier.
In our previous article we have stored the public key in encided form in a file with an extension .pubkey and the signature bytes in a file with extension .dsa . So in order to verify first we will try to read the key bytes and pass them to X509EncodedKeySpec object. Then use the KeyFactory to reconstruct the public key. Next we have to create the Signature object with the same algorithm as earlier and initialize with the public key.
In our previous article we have stored the public key in encided form in a file with an extension .pubkey and the signature bytes in a file with extension .dsa . So in order to verify first we will try to read the key bytes and pass them to X509EncodedKeySpec object. Then use the KeyFactory to reconstruct the public key. Next we have to create the Signature object with the same algorithm as earlier and initialize with the public key.
Labels:Security  0
comments
Sunday, July 27, 2014
Today in this article I will show you how to solve 01 Knapsack problem using the concept of dynamic programming in Java. This problem can also be solved by recursion but the problem is that it will result in solving of already solved subproblem. So we will be using dynamic programming to solve by storing the results of solved subproblems. Also this technique can be used to solve the problem in polynomial time. The complexity of solving it using this algorithm is O(n*W).
What is 0/1 Knapsack problem ?
The knapsack or rucksack problem is a problem in combinatorial optimization. Here there are a set of items(n) which has a profit value(v) and weight(w). There is a bag which has a maximum capacity(W). Now the problem is to fill the bag with the following restrictions :
1. You can either choose an item completely or reject it. (0 or 1)
2. The total weight of bag must not exceed its maximum capacity W. i.e. (Sum of w[i]) <= W
3. The total value or profit of items chosen must be maximum. i.e. Sum of p[i] is maximum
where 0 < i <=n.
How to solve 0/1 Knapsack problem in Java ?
Step1: Structure: Characterize the structure of an optimal solution.
– Decompose the problem into smaller problems, and ﬁnd a relation between the structure of the optimal solution of the original problem and the solutions of the smaller problems.
What is 0/1 Knapsack problem ?
The knapsack or rucksack problem is a problem in combinatorial optimization. Here there are a set of items(n) which has a profit value(v) and weight(w). There is a bag which has a maximum capacity(W). Now the problem is to fill the bag with the following restrictions :
1. You can either choose an item completely or reject it. (0 or 1)
2. The total weight of bag must not exceed its maximum capacity W. i.e. (Sum of w[i]) <= W
3. The total value or profit of items chosen must be maximum. i.e. Sum of p[i] is maximum
where 0 < i <=n.
How to solve 0/1 Knapsack problem in Java ?
Step1: Structure: Characterize the structure of an optimal solution.
– Decompose the problem into smaller problems, and ﬁnd a relation between the structure of the optimal solution of the original problem and the solutions of the smaller problems.
Labels:Algorithms  1 comments
Tuesday, July 22, 2014
Today I am going to show how to convert a postfix expression to an infix expression using stack in Java. In an earlier post here we ahve shown how to convert an infix expression to postfix using stack. Here we will just try to do the reverse. Here in our example we will be able to convert any postfix expression to infix irrespective of the operators. A number of parenthesis may be generated extra which were not there in original infix expression. The parenthesis that may be generated extra will have no impact on actual expression, they are just for better understanding. The process of postfix to infix conversion is summarised below 
Labels:Algorithms  1 comments
Saturday, July 12, 2014
Today I am going to deal with an e3xcellent feature of the Java Concurrency framework. You can consider it as one of the most basic things of the framework. Here I will show you how to use the Executor with a simple demo example. You would like to know why to use Executor? Earlier you must have learnt during your basic learning on Java threads, that whenever you will have to do multithreading you will have to create a task either implementing Runnable interface or extending Thread class. Then you would have to start the thread created by calling start() method. This is actually very lowlevel implementation where you are dealing with threads. This is completely alright for small applications. But when you are handling large applications, you would never like to handle and manage threads directly, as your main work is to deal with the task properly and concentrate on that. So keeping that in mind, her comes the advantage of Executor where you only have to create the task and
Labels:Threads  0
comments
Saturday, July 5, 2014
Today I am going to discuss with the first step of JPA  Java Persistence API. JPA helps you in objectrelational mapping and reduces a lot of task of coders, otherwise they have to write a lot of JDBC codes. All those things are done automatically by the Persistence provider. Throughout all the topics related to JPA that we will cover will consider EclipseLink as the JPA provider.
After all necessary setups, the first thing you will have to do is to write a JPA entity. Many IDE like Eclipse can automatically create it, but we will show how to write it and what are the steps. You must have seen the JavaBean style classes. Here our first task is to write a class in that style only. Next we will make some modifications to make it a JPA entity.
After all necessary setups, the first thing you will have to do is to write a JPA entity. Many IDE like Eclipse can automatically create it, but we will show how to write it and what are the steps. You must have seen the JavaBean style classes. Here our first task is to write a class in that style only. Next we will make some modifications to make it a JPA entity.
Labels:J2EE  0
comments
Subscribe to:
Posts
(Atom)
Labels
 Algorithms (7)
 Annotation (3)
 Files (6)
 Generics (3)
 Graphics2D (5)
 Graphics2DImages (7)
 Inheritance (2)
 J2EE (9)
 Java 8 (4)
 Java FAQs (19)
 JDBC (3)
 Networking (2)
 Packages (1)
 Reflection (4)
 Security (7)
 Sorting (2)
 Swing (3)
 Threads (3)
 Utils (3)
Popular Posts

 UPDATE  I have updated the code on request of some followers so that they can directly...

Today I will show you how you can implement Bankers algorithm in Java. The Banker's algorithm is a resource allocation and deadlock a...

UPDATE I have updated my post so that now it can detect IE 11. This modification was necessary as t...

Today I am going to post a program that will be able to produce all the mColorings of a given graph G. What is mColoring : The problem st...

Today I am going to show how to convert a postfix expression to an infix expression using stack in Java. In an earlier post here we ...

Today in this article I will tell you how to convert an infix expression to postfix expression using stack. This is an important applicat...

Today I am going to show you how you can generate and validate captcha. A CAPTCHA (an acronym for "Completely Automated Public Turin...

Today I will show you how to do 256bits AES encryption and decryption of a file in Java. You can write codes for AES  128bits without d...
Links
About Me

Nirupam Das
 I am a student of BTech Computer Science Engineering from RCCIIT,Kolkata. I am a crazy lover of Java and wants to settle as a Java developer. I have a seven years Java experience with an application developer experience for 2 years. Recently from March 2012 I am a registered S40 app developer for Nokia and has corrected an app of them. I am currently writing blogs to encourage and grow interest in all those who don't know or learning Java.