One way hash in Java

Ads

 
 

Share on Google+Share on Google+

Umesh
One way hash in Java
1 Answer(s)      6 years and 10 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,
Ads
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

Ads









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
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
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
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 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 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
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads