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



Home Answers Viewqa Java-Beginners One way hash in Java

Have Programming Question? Ask it here!
 
 
 


Umesh
One way hash in Java
1 Answer(s)      4 years and a month 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
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 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
Hash Map
Hash Map  how to add the hash map objects in the list and iterate the objects
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
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 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
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
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
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
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
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
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;  
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"  
Balance multi-way tree implimentation reating database - Java Beginners
Balance multi-way tree implimentation reating database  I am doning a project in which I have to create a database product in java where user can... database like Access,MySQL.As we know database is based on Balance multi-way tree
which one is better, Flex or Java?
which one is better, Flex or Java?  Does flex has a scope to survive in IT? Which one of these two, Flex and Java, has a better scope of survival
one dimensional array using java
one dimensional array using java  design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
Execute the java program using one processor
Execute the java program using one processor   Write a program to print the number series 1, 2,3, 4â?¦.100 using java programming language in dual core computer a) Execute the program using one processor b) Execute
Decreasing process time by caching through the Hash Table in Java
Decreasing process time by caching through the Hash Table in Java... by your java program. You can easily improve the process completion time... operation in plain way and completing operation by caching and show the whole
File copy from one directory to another in java
directory in Java. I have to write a program in my application for copying one file... for copying the file from one directory to another directory in Java...File copy from one directory to another in java  I am trying to find
How to generate hash code of Zip file.
How to generate hash code of Zip file. In this tutorial, we will see how to generate hash code of zip file entries. The ZipFile   class is used to read... returns hash code of associated method. enumeration
Any one can help me? - Java Beginners
Any one can help me?  CAN any of u help me to do this java codes for the interface given below? thanku the user will be given jumbled words of animals at first. Each correct answer will be given 5 points. 5 points
one interview question - Java Interview Questions
one interview question   Hello, In one of my interview the interviewer ask one question "what are the problems you faced during project implementation", can any body tell me what should be the appropriate answer
Three Way Matching
Three Way Matching  hello, What is Three Way Matching?   hii, In Three way matching the following documents are compare:- Purchase order Receipt of Items/Packing slip Invoice
Many Public Classes in One File - Java Tutorials
Many Public Classes in One File 2003-10-13 The Java Specialists' Newsletter [Issue 080] - Many Public Classes in One File Author: Dr. Heinz M. Kabutz... Java classes in China. I was talking about Java only allowing one public
how to display one image on jsp through java
how to display one image on jsp through java  Hi, I wanted to display one image on my jsp file like social networking sites. But the scenario is that the image file is not inside the project folder. That is inside the C
Java example to calculate the execution time
will describe you the way that how one can calculate or get the execution time of a method or program in java. This can be done by subtracting the starting time... Java example to calculate the execution time  
one attribute of type int - Java Beginners
one attribute of type int  hi friends can anyone help me understand this question:- Define a class called Month. Your class will have one attribute of type int to represent a month (1 for January, 2 for February, and so
Counting the highest sequence of zeros and one's - Java Beginners
Counting the highest sequence of zeros and one's  Count the highest sequence value of '0's and '1's. for a given string with zeroes and ones. Input: You should ask user to enter any bit string with zeros and ones sequence
does any one have sudoku in java - Java Beginners
does any one have sudoku in java   i need soduko in java using applets
java program to copy the contents of one folder to another folder
java program to copy the contents of one folder to another folder  java program to copy the contents of one folder to another folder   Have a look at the following link: Java Copy one folder to another
How to copy a file in java
a content of one file to another file. In java, File API will not provide any direct way to copy a  file.  What we can do is, read a content of one.... In another way we can copy using File I/o Stream. Example:  Java Code to copy
 

 

 

DMCA.com