One way hash function in java

Simply i want to save a password entered to a java program and save it in a MySQL database
Here I want to encrypt that password and save it in the database.... I prefer one way hash function encryption because it fulfills my need.
SHA-1 is the best in java now as I read from a article, is it?
What I need is that if someone can post a complete code which uses SHA-1 (if it is the best preferred one).
I've tried some codes published in the web but didn't work
one code worked very well but when I entered characters like "@#$%%" it failed.
Thank You!!!

797241 wrote:
I've search using your key terms and got a good code that works ("java sha-1 example")
thanks for that
I didn't got that when i was searchingHard to believe.
So suggesting that working link was enough though you've put some other annoying comment tooIt is considered extremely bad mannered just to ask for code. If you have presented code that has problems and ask for help in fixing the problems you will normally get help but just to ask for code implies you are very lazy.
thanks for that too
I would rather prefer if you would have written "You are not going to get an answer, get the hell out of here!!!"Now that would have invoked the wrath of the moderators!
P.S. Just using a SHA-1 digest is insecure as the result is open to a dictionary attack. You should use a randomly seeded digest with both the random value and digest value being stored in the database.

Similar Messages

  • How to encrypt password with hash function in Java?

    Hello, everybody!
    I will need to store user passwords in a database, but for stronger security I want to store these passwords hashed, so I know I will need a column for the password and for the salt value.
    So, I'd like that you indicate me a very good article or tutorial (preferable from Sun) that shows me how to use Java to encrypt and decrypt passwords with hash. It doesn't necessarily need to deal with database. I can implement this part myself after seeing how Java manage encryption with hash functions.
    Thank you very much.
    Marcos

    I will tell you more precisely what I want to get better for you to help me.
    As I said I implemented in .NET what I need to implement in Java now. In my
    database I have a table with this structure (I omitted that columns that are not
    necessary to our discussion):
    CREATE TABLE EMPLOYEES
    ID NOT NULL PRIMARY KEY,
    PASSWORD VARCHAR(40), -- password encrypted
    HASH_SALT VARCHAR(10) -- salt value used to encrypt password
    So, in the table I have a column to store the password encrypted and a column to
    store the salt value.
    Below is a little utility class (in C#) that I use to generate the salt and
    the hashed password.
    public static class PasswordUtilities
        public static string GenerateSalt()
            RNGCryptoServiceProvider encoder = new RNGCryptoServiceProvider();
            byte[] buffer = new byte[5];
            encoder.GetBytes(buffer);
            return Convert.ToBase64String(buffer);
        public static string EncryptPassword(string password, string salt)
            string encryptedPassword =
                FormsAuthentication.HashPasswordForStoringInConfigFile(
                password + salt, "SHA1");
            return encryptedPassword;
    }As you can see, the class is fairly simple. It only has two methods: one to
    generate the salt value that will be used to encrypt the password and another
    one to encrypt the password. The method HashPasswordForStoringInConfigFile of
    the FormsAuthentication class is what really hash the password with the salt
    value. This class belongs to the .NET library, so we can't see its source code,
    but it doesn't matter for our discussion as I know that we can implement
    something similar in Java.
    Below is a little sample code showing the use of the utility class above to
    encrypt a password.
    public class Encrypt
        public static void Main(string args[])
            string password = "Secret";
            string salt = PasswordUtilities.GenerateSalt();
            string encryptedPassword = PasswordUtilities.EncryptPassword(password, salt);
            // now I store 'encryptedPassword' in the PASSWORD column and 'salt'
            // in the HASH_SALT column in the EMPLOYEES table.
    }To verify if a password is correct I can use the code below:
    public class VerifyPassword
        public static void Main(string args[])
            string password = GetPasswordFromUser();
            // Let's assume that employee is an instance that corresponds to a row
            // in the database and the properties HashSalt and Password correspond
            // to the HASH_SALT and PASSWORD columns respectively.
            Employee employee = GetEmployeeFromDatabase(1);
            string salt = employee.HashSalt;
            string encryptedPassword = PasswordUtilities.EncryptPassword(password, salt);
            bool passwordMatch = employee.Password.Equals(encryptedPassword);
            System.Console.WriteLine(passwordMatch);
    }The only thing that interest me in this discussion is the PasswordUtilities class.
    As you saw its code is in C#, using the .NET framework libraries.
    What I want is to have this same little class coded in Java, to generate the salt
    value and to encrypt the password passed in using salt value generated. If you could
    help me to do that with articles that have what I want or with code that already do
    that I would really appreciate.
    Thank you in advance.
    Marcos

  • HASH FUNCTION IN JAVA

    i need help!!
    i have to create a program in java in which i want to compare passwords by using hash function.More specifically,the parameters of hash should be like this hash(password,salt).
    which is the library that i have to use and how can i call it in main function?
    thank you!
    plz respond as soon as possible!

    The same way you would call it in any other method :) You should start with the JCE develop guide and go from there. The more reading you can do on cryptography the better. If you understand the concepts, the Java code will become easier to write.
    http://download.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#MDEx

  • Java API for 1-Way Hash

    Hi guys,
    Does anyone know if Java has API's to perform one-way hash transformation?
    Please, could someone let me know!
    Thank you,
    Leon

    The crypto APIs do, although you need a provider for the actual hash. Have a search through the Cryptography forum http://forum.java.sun.com/forum.jsp?forum=9

  • Hash - one-way function

    I am developing an applet in the card which needs a one-way function to encrypt the variable I am trying to send. I don't want the other party to know which my variable is, so that is why I need to send it cipher. The other party will have the same data and applying the same function can know if mine was correct but without getting new information.
    Is there any on-way funcion like HASH function implemented on the card?. How can I implement such a thing?

    Check the class MessageDigest in javacard.security, there you can perform a one-way function.

  • FM call from Variant Function in JAVA SCE

    Hello,
    I have an issue with Variant Configuration in CRM WEB UI / WebShops.
    We have created a variant function in ECC to read/pull a customer master value (KNVV table).  This is working fine in ECC & got the desired result.
    Now we need replicate the same in CRM. For this we need to create KB, Version & write a variant function in Java class in SCE. In that variant function we need to call a function module and get the customer master / Business partner value as similar to ECC process described above.
    But we see that the SAP standard is not supporting FM calls from VF in Java. i.e. we are unable to call the JCO call to a CRM function module from SCE.  The package for User defined classes "com.sap.sce.user" and the method inside it public boolean execute(fn_args args, Object obj) { ..... } has no option to make a FM call.
    Has anyone faced the similar requirement and has any resolution for this? 
    Thanks,
    Surya.

    Hi Eric,
    You sound quite familiar with the variant functions. I am also working on IPC-SCE
    variant functions for few years now.
    We have a situation where I am building some debug logs in one java variant function and want to display it to the web UI at some condition.
    Is there any object(like context etc.) that IPC server-side and Webapps share?
    I can write that log to a text file and read it from web ui ... but I wanna avoid that.
    Is there any other way you know of???
    Regards,
    Ruchika

  • Help with Hash Function in Properties

    Hi, I need to know the algorithm of the Hash Function that is used by Java in its HashMap, Properties, etc... classes.
    Can I get it somewhere or is it private? I need it for documentation purposes.
    Thanks!
    Sigurd

    Hi.
    You can download the source for the entire JDK from the usual download locations, so you can see the details of the implementation there. If you're looking for a higher level description, I don't know where you'd find that, other than a few pages which document general ways to get well distributed hashes; look at http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf for an example of this - a chapter from the mighty Joshua Bloch's 'Effective Java'.
    Regards,
    Lance

  • Error PLS-00306 during calling PL/SQL function from Java

    Hi all,
    I am facing a problem during call of oracle PL/SQL function from java using CallableStatement.
    I receive following error message.
    java.sql.SQLException: ORA-06550: line 1, column 13:
    PLS-00306: wrong number or types of arguments in call to 'EXPORT_HIST_ALARMS_FUNC'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    As per above error EXPORT_HIST_ALARMS_FUNC in oracle has this signature.
    CREATE OR REPLACE FUNCTION EXPORT_HIST_ALARMS_FUNC(startDateTime VARCHAR2, endDateTime VARCHAR2, meType VARCHAR2) RETURN VARCHAR2 IS
    END EXPORT_HIST_ALARMS_FUNC;
    Above function I have called following way in java.
    String sql = "begin ?:= EXPORT_HIST_ALARMS_FUNC(?, ?, ?); end;" ;
    CallableStatement cStatement = null;
    cStatement = connection.prepareCall(sql);
    cStatement.registerOutParameter(1,Types.VARCHAR);
    cStatement.setString(2,startDateTime);
    cStatement.setString(3,endDateTime);
    cStatement.setString(4,meType);
    cStatement.execute();
    msg = cStatement.getString(1);
    Actually above function requires three input parameters and one return parameter.
    During execution of above java code it throws SQLException and shows PLS-00306: wrong number or types of arguments in call to 'EXPORT_HIST_ALARMS_FUNC' error.
    I have run this function directly from oracle with three parameters and run successfully and finally it returns string.
    But I am unable to figure out why it doesn't run from above java code.
    Please help regarding this.
    Thanks.
    Regards,
    Shardul Banker

    Try this:
    String sql = "begin ?:= EXPORT_HIST_ALARMS_FUNC(?, ?, ?); end;" ;
    CallableStatement cStatement = null;
    cStatement = connection.prepareCall(sql);
    cStatement.registerOutParameter(1,Types.VARCHAR);
    cStatement.setString(1,startDateTime);
    cStatement.setString(2,endDateTime);
    cStatement.setString(3,meType);
    cStatement.execute();
    msg = cStatement.getString(1);Regards,
    Martijn Teigeler
    Edited by: mTeigeler on Oct 13, 2007 10:22 AM

  • How to access C/C++ functions in Java using existing .dll library

    Hi JNI Guru's,
    I am having well written API in C/C++.This C/C++ files are made into *.dll files.The api are working fine.
    I wan't access the C/C++ api functions in Java., just using System.LoadLibrary("*.dll").Is it possible.I kindly request you to suggest some examples and how to do this.
    Its Urgent !.
    Thanks and Regards,
    V K LAL

    In general you cannot simply access dlls that have already been written. The DLLs called using JNI must conform to JNI calling standards.
    This means you will probably have to write one or more "wrapper" dlls which a) provide the correct JNI interface, and b) call the existing dlls.
    There are some programs around that claim to be able to generate such wrappers. Try a google search for "wrapper", "jni", "generate".
    The JNI tutorial covers creating wrappers.

  • The troubles with creating SQL function in Java

    Hi!
    I use Oracle 10g and connect to it from Java application. I need in creating SQL functions from Java code.
    In Java I have:
    Statement stm = null; try{     stm = dbConnection.createStatement();     stm.executeUpdate( query ); }catch(SQLException ex){     throw ex; }finally{     try{ stm.close(); }catch(Exception ex){ stm.close(); } }
    And I'm passing the next SQL function:
    create or replace function get_me return number is
    result number;
    begin
    select 5 into result from dual;
    return result;
    end;
    This code is run successful, but I can't call this funtion, because it has status Invalid
    I'm looked the next error: PLS-00103: Encountered the symbol "" when expecting one of the following: . @ % ; is authid as cluster order using external character deterministic parallel_enable pipelined aggregate
    But I don't understand, What the matter? From Oracle Enterprise Manager I can create this function without problems. So, I wrote the wong Java code. Also, I can't find my error :(
    May be, do u have the some ideas?
    Thank you very much!

    Post the whole pl/sql code please.
    To run PL/SQL from within java you'll need callablestatement.
    [here |http://www.idevelopment.info/data/Programming/java/jdbc/PLSQL_and_JDBC/CallPLSQLFunc.java] an example : http://www.idevelopment.info/data/Programming/java/jdbc/PLSQL_and_JDBC/CallPLSQLFunc.java

  • CALLING a STORED SQL FUNCTION from  Java 1.1.8

    I am trying to execute a stored function in JAVA 1.1.8, from an Oracle
    8i Database. My stored function is simple, it converts an Input Number to an output TIME string. I am unsure how to code the call from Java. Are SQL STORED PROCEDURES treated the same as SQL STORED FUNCTIONS? Do you use the CallableProcdure class or something else?
    Thanks for your input.

    yep - same way. Except no return value.

  • Active Directory: One Way Trust from NT Domain to 2003 Domain being upgraded to 2012 R2

    We have an old legacy NT 4 domain that is slowly being decommissioned. (Slowly is the key word) Currently there is a one way External Trust between those NT 4 domains and a child domain that is at 2003 functionality. We are in the middle of upgrading
    those child domain and the root domain to 2012 R2.  My only concern right now and I can't seem to find concert proof either way, but will that external one way trust break when upgrading the forest and domain functionality to 2012 R2 once we
    have all our DC's upgraded?  I have read articles on how to get that trust to work in a 2008 R2 domain and of course it is working with the existing 2003 domain.
    In theory the trust should break, correct?  However, I know there are some security changes among other things in 2012 that may or may not work. 
    Kristopher Turner | Not the brightest bulb but by far not the dimmest bulb.

    Yes.  We are working with the client to migrate any dependencies off these 3 NT legacy domains. We will be able to decommission 2 of the 3 without any issues. However, they still have an old NT box running SQL 6.5 databases for a application still in
    production. Yes, they are very aware that NT isn't supported, that that version of SQL isn't supported, and that this will hold up their upgrade.
    Our plans for them will be to deploy all new Windows Server 2012 R2 domain controllers but keep the domain and the forest functionality at 2003 in order to support that final NT Legacy domain until they can get that application migrated.
    Once that NT domain is decommissioned then we can raise the functionality of the rest of their domains from 2003 to 2012 R2.
    Kristopher Turner | Not the brightest bulb but by far not the dimmest bulb.

  • Lookiing for example of a user define aggregate function in Java

    I want to write an aggregate function in Java. Every example I found is in PL/SQL.
    I have written my fair share of JSPs, but this is different in that it is methods off an object.
    The documentation says it can be done in Java, but it's not clear to me how to define the ODCIAggregateInitialize, ODCIAggregateIterate, ODCIAggregateTerminate, and ODCIAggregateMerge methods.
    If any one can point me to, or send me, an example, I would be very grateful.
    TIA

    Hii Greg:
    You can find the code to implement a Domain Index for Oracle which uses ODCI Api in Java at.
    http://dbprism.cvs.sourceforge.net/viewvc/dbprism/ojvm/src/java/org/apache/lucene/indexer/LuceneDomainIndex.java?revision=1.29&view=markup
    This is the code of the implementation of the Lucene Domain Index:
    http://docs.google.com/Doc?id=ddgw7sjp_54fgj9kg
    The strategy to implement an use aggregate function is similar to implement a Domain Index.
    The PLSQL wrapper for the above code is:
    http://dbprism.cvs.sourceforge.net/viewvc/dbprism/ojvm/db/LuceneDomainIndex.sql?revision=1.20&view=markup
    Take a look at the code and if you have another question just drop me an email or post again into this list.
    Best regards, Marcelo.

  • Other ways to start workflow java listener

    Hi all,
    Is there any other way to start workflow java listener apart from this procedure,
    type'n the following command :
    wfjvlsnr.bat "<user_name> <connect_string>
    Regards,
    P.Kalyan

    [url http://forum.java.sun.com/thread.jsp?forum=57&thread=509229]Here is one way.

  • Hash function in directory server

    Dear all,
    We have a very large database so when we setup our LDAP server, we add a number(between 0 and 256) ou to LDAP schema. The number is calculated from the user email address with a hash function.
    However we have such a problem when we want to migrate our old system to JMS. How can we let JMS to know the hash number from user's email? Is there any way to add a hash function to JMS's directory-access-API so that JMS would use both user's email and the hash number to access LDAP?
    Thanks for any help from you.
    Alex

    Dear all,
    We have a very large database so when we setup our
    LDAP server, we add a number(between 0 and 256) ou to
    LDAP schema. The number is calculated from the user
    email address with a hash function. This sounds like an unneeded complication. Why?
    >
    However we have such a problem when we want to
    migrate our old system to JMS. How can we let JMS to
    know the hash number from user's email? Is there any
    way to add a hash function to JMS's
    directory-access-API so that JMS would use both
    user's email and the hash number to access LDAP?You might look at the domain_uplevel setting in option.dat, but I'd personally rather have you loose the hash.
    We have deployments without such complications, into the several million Directory entries, with no problem, and no hash.
    >
    Thanks for any help from you.
    Alex

Maybe you are looking for

  • How to install windows 7 on 2011 macbook air?

    I'm planing to buy a mid 2011 macbook air. I want to install windows 7 using boot camp on it. can i install windows 7 without any external cd/dvd drive??

  • XI Integration scenario for material replication from SRM to SRM-MDM

    Hi Guys, We are working with the following landscape: SRM Server 5.5 ECC 6.0 SRM-MDM 5.5 SP6 PI 2005_1_700 SP0006 I have a question for you about replication of the material master form SRM EBP to SRM-MDM. In XI we are trying to configure this scenar

  • Corruption in redo log

    Hi, We are using Oracle 7.3 and we had a system crash. After i boot up the system and tried to open the database, i got a message that one of the redo log(current) was corrupted and hence the database cannot opened. We are in nonarchived mode and sin

  • ASM error

    when asm instance starts, i get an error LRM-00109: could not open parameter file. Please help me

  • Redo Log Last modified date

    Hi All, Couple of day's back we have set Hot back up mode for 11g database server from cold back up, after this reado log's last modified date is not getting updated and redolog last modified date is get's updated only when we restart the database, T