One way hash in Java

One way hash in Java

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,
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...;= (Integer) hashtable.get("One");   
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
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
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   ... with complete code is provided for the best illustration of the way of hash table... arguments one is the key of the hash table and another is the value corresponding
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
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
Best way to learn Java programming
|| []).push({}); What is the best way to learn Java programming? I think one...Best way to learn Java programming  Hello Guys, I am working... the best way to learn Java programming? Thanks (adsbygoogle
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 methodsADS_TO_REPLACE_1 ïâ??Â... there (a bit different from the one presented in the lecture). ïâ??· A method
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
What is the best way to learn java
for the guide for learning Java. What is the best way to learn java? Give me clear path...What is the best way to learn java  Hi, Beginners always finds... and found difficult in getting started. Now I am planning to learn Java but now
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
Example to show Hash map exception in java
Example to show Hash map exception in java  ... method to key-value pairsADS_TO_REPLACE_2 Understand with Example Hash map in java...;= new Hash Map():-This is the way for creating a HashMap.Here we have
Hash Map
Hash Map  how to add the hash map objects in the list and iterate the objects
hash value
hash value   what is the meaning of this line private int hashValue = 0
Maven Repository/Dependency: com.github.romix | java-concurrent-hash-trie-map
Maven Repository/Dependency of Group ID com.github.romix and Artifact ID java-concurrent-hash-trie-map. Latest version of com.github.romix:java-concurrent-hash-trie-map dependencies. # Version Release Date
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
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.   ADS_TO_REPLACE_1
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
What is the fastest way to read a file in Java?
What is the fastest way to read a file in Java?  Hi, I am reading my.... Let's know the fasted way of reading the text. Thanks   Since you... of Java. Here is the sample code you can use: FileInputStream fstream = new
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
What are some way to learn Java quickly?
What are some way to learn Java quickly?  Hi, What are some way to learn Java quickly? I want to know the tricks or tips for learning Java programming quickly. What can be easy steps to learn Java. Thanks   !alt
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... provides you to put some string in the Hash Table of Java and get
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
What is the best way to learn Java on my own?
What is the best way to learn Java on my own?  Hi, I am new to job... tutorials in Java. What is the best way to learn Java on my own?   Hi.... I am interested in making my career in Java software programming. I want
What is the best way to filter a Java Collection?
What is the best way to filter a Java Collection?  Hi, I have... the persons having personAge >14. How achieve this? What is the best way to filter a Java Collection? Thanks   Hi, In Java 8 you can use
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..., Java is way ahead and it seems to stay that way by being an open source
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 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;  
ModuleNotFoundError: No module named 'hash'
ModuleNotFoundError: No module named 'hash'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'hash' How to remove the ModuleNotFoundError: No module named 'hash' error
ModuleNotFoundError: No module named 'hash'
ModuleNotFoundError: No module named 'hash'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'hash' How to remove the ModuleNotFoundError: No module named 'hash' error
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
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
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"  
ModuleNotFoundError: No module named 'int-hash-int-hash-lib'
ModuleNotFoundError: No module named 'int-hash-int-hash-lib'  Hi...: No module named 'int-hash-int-hash-lib' How to remove the ModuleNotFoundError: No module named 'int-hash-int-hash-lib' error? Thanks   Hi
What are the best way to learn Spring & Hibernate Framework for a Java beginner?
What are the best way to learn Spring & Hibernate Framework for a Java beginner?  Hi, What are the best way to learn Spring & Hibernate Framework for a Java beginner? I want to learn these technologies ASAP. Thanks
What are the best way to learn Spring & Hibernate Framework for a Java beginner?
What are the best way to learn Spring & Hibernate Framework for a Java beginner?  Hi, What are the best way to learn Spring & Hibernate Framework for a Java beginner? I want to learn these technologies ASAP. Thanks
What are the best way to learn Spring & Hibernate Framework for a Java beginner?
What are the best way to learn Spring & Hibernate Framework for a Java beginner?  Hi, What are the best way to learn Spring & Hibernate Framework for a Java beginner? I want to learn these technologies ASAP. Thanks
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
How can I master Java in one month?
How can I master Java in one month?  Hi, I wish to learn Java programming in one month. I have little experience in c programming and PHP programming. Is there any way to learn Java quickly. How can I master Java in one month
Version of com.invincea>spark-hash dependency
List of Version of com.invincea>spark-hash dependency
ModuleNotFoundError: No module named 'allium_hash'
ModuleNotFoundError: No module named 'allium_hash'  Hi, My Python... 'allium_hash' How to remove the ModuleNotFoundError: No module named 'allium_hash' error? Thanks   Hi, In your python environment

Ads