Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners One way hash in Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Umesh
One way hash in Java
1 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners


Hi,

What is one way hashing. How to implement it in Java. I've to compare the contents of two files by generating their hash value in Java.
Please give some examples.

Thank You,

Advertisement
View Answers

July 16, 2010 at 3:38 PM


Hi Friend,

A one-way hash function is used to create digital signatures, which in turn identify and authenticate the message.

Example:
********************

import java.util.*;
import java.security.*;
public class Hashing {

public static String convert(String st)throws Exception{
byte[] by = st.getBytes();
MessageDigest md = MessageDigest.getInstance("MD5");
md.reset();
md.update(by);
byte messageDigest[] = md.digest();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
buffer.append(Integer.toHexString(0xFF & messageDigest[i]));
}
return buffer.toString();
}
public static void main(String[]args)throws Exception{
Scanner input=new Scanner(System.in);
System.out.print("Enter text: ");
String text=input.nextLine();

String st=Hashing.convert(text);
System.out.println(st);
}
}

Thanks


Related Tutorials/Questions & Answers:
One way hash in Java - Java Beginners
One way hash in Java  Hi, What is one way hashing. How... their hash value in Java. Please give some examples. Thank You,  Hi Friend, A one-way hash function is used to create digital signatures, which in turn
Java One way Hashing
Java One way Hashing One way hash functions are a major tool in cryptography. It is used to create digital signatures, which in turn identify and authenticate the message. It can have other practical applications as well
Advertisements
hash function for java strings
hash function for java strings  hash function for java strings   int hash=7; for (int i=0; i < strlen; i++) { hash = hash*31+charAt(i
Hash value is not same - Java Beginners
Hash value is not same  Hi, I've two Excel files with same data. One is in Excel 2003 (.xls) format and other one is in Excel 2007 (.xlsx) format. I've generated one way hash using SHA-1 algorithm. But the hash value of Excel
Java Hash table
Java Hash table   Hi I have to create code to allow the insertion of a sequence of numbers into a hash table,using a fixed size hash table. Then i... of numbers; insert these into the hash table. Can anyone give me any help
Example to show Hash table exception in java
of using exception class in java. This tutorial describes  the way to handle Hash... Example to show Hash table exception in java...) hashtable.get("One");   System.out.println("
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
Usage of Hash Code - Java Interview Questions
Usage of Hash Code  Dear sir, What is Hashcode in Java and What is its usage? Thanks and Regards M.KehtraBalan  Hi Friend, A hashCode is a way of computing a small (32-bit) numeric key from a long
Simple Hash Table implementation in Java
Simple Hash Table implementation in Java       This section describes the complete Hash Table... is provided for the best illustration of the way of hash table manipulation
java program(Hash Table) - Java Beginners
java program(Hash Table)  Store the names of 10 major cities and the names of corresponding countries in a hash table. Accept the name of a city... argument or specifies a city that is not in the hash table.  Hi friend
Using Arraylist or Hash Map - Java Interview Questions
Using Arraylist or Hash Map  what could b the pros and cons changing between Hash Map to Array List
what is difference between one-way data binding and two-way data binding?
what is difference between one-way data binding and two-way data binding?  what is difference between one-way data binding and two-way data binding? Thanks
Simplest way to print an array in Java
Simplest way to print an array in Java  Simplest way to print an array in Java
Hash table
Hash table  Hi guys.. I have question about hash table How to implement a hash table of English words? with these methods ï??· A method put(s... different from the one presented in the lecture). ï??· A method remove(s), which
Best way to reading file in java
Best way to reading file in java  Hi, As a beginner I want to learn about Java programming and make a program for reading a text file in java. What is the best way for reading file in Java? Thanks
Hash Map
Hash Map  how to add the hash map objects in the list and iterate the objects
Example to show Hash map exception in java
Example to show Hash map exception in java  ...-value pairs Understand with Example Hash map in java is same as the Hash table...():-This is the way for creating a HashMap.Here we have created an empty  Hash Map
Hash Table for maintaining popup menus in Java
Hash Table for maintaining popup menus in Java  ... of maintaining popup menus through hash table in your Java program. This section... to create and maintain popup menus in Java. All the elements listed in the hash
Thread Access through the Hash Table in Java
Thread Access through the Hash Table in Java       Here, you will learn about how a thread is accessed by using the hash table in Java.      Here
hash value
hash value   what is the meaning of this line private int hashValue = 0
Partial Search from Hash Table in Java
Partial Search from Hash Table in Java   ... string in the Hash Table through the Java program and get these string easily. Here... to put some string in the Hash Table of Java and get it for searching. This is done
java array sorting manual way
java array sorting manual way  Hi, Anyone has any sample code on how to sort a array manually without using the inbuild sorting algorithm? Thanks
hash map
hash map  write a program in hash map , that shows the value in asending order. but not key value. ex: key value ==== ===== k5 ashutosh k1 babita k7 debasis k2 vikas plz help me
What is an efficient way to implement a singleton pattern in Java?
What is an efficient way to implement a singleton pattern in Java?  What is an efficient way to implement a singleton pattern in Java
Creating a Hash Table
Creating a Hash Table : Java Util       This section explains the implementation of the hash... of entries which have to entered into the hash table and takes one-by-one key
Easiest way to learn Java
There are various ways to learn Java language but the easiest way to learn Java is online. RoseIndia provides Java courses online that helps beginners..., application or operating system. When compared to other languages, Java is way
hash map
hash map  how to add object of test class in a hashmap test class is as follows class test{ String str1; String str2; String str3; int i1; int i2; } values of instance variable is coming from different database tables;  
Writing and reading from/to a serialized file through Hash Table in Java
Writing and reading from/to a serialized file through Hash Table in Java... illustrates you how to read and write from/to a serialized file through the hash table in Java. This section provides an example with the complete code of the program
What is the best way to write to file in Java?
What is the best way to write to file in Java?  I am creating a program in Java which writes into a text file. What can be the be best method to write to a text file in Java? Since my program will continuously write the data
Best way to learn Java
Best way to learn Java is through online learning because you can learn it from the comfort of your home. Online learning of Java is also free, the only... that provide you Java guides or courses online, even providing certificates
Hash-function: "weakly collision-free" and "strongly collision-free"
is said to be one-way if it is hard to invert, where ``hard to invert'' means... collision-free hash function. A strongly collision-free hash function H is one...Hash-function: "weakly collision-free" and "strongly collision-free"  
 

 

 

DMCA.com