Search This Blog

Saturday, January 3, 2015

Implement Message Digest algorithm

SHA1 message digest for securing your string for storing into database.

Firstly create a method called sha1(String password). Here pass the password as a string as a parameter.

String sha1(String input) throws NoSuchAlgorithmException {
MessageDigest mDigest = MessageDigest.getInstance("SHA1");
byte[] result = mDigest.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16)
return sb.toString();

Now just get the input from user and store it using this method into database

String shapassword = sha1(masterPassword.getText().toString().trim());

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.