Android Snippet: MAking a md5 hash from a string in Java
Join the DZone community and get the full member experience.
Join For FreeSecurity is always an issue when you connect your application to the
web. Here is a nice little method that will let you implement md5
encryption.

private String md5(String in) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); digest.reset(); digest.update(in.getBytes()); byte[] a = digest.digest(); int len = a.length; StringBuilder sb = new StringBuilder(len << 1); for (int i = 0; i < len; i++) { sb.append(Character.forDigit((a[i] & 0xf0) >> 4, 16)); sb.append(Character.forDigit(a[i] & 0x0f, 16)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
How to use:
String unsecurepassword = "unhackablepassword"; String securepassword = md5(unsecurepassword );Please mind that md5 is not decryptable. If you need an encryption that you can reverse you will have to look into something other then md5. (AES for example)

Snippet (programming)
Java (programming language)
Strings
Android (robot)
Data Types
application
security
Published at DZone with permission of Mark Mooibroek, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Getting Started With the YugabyteDB Managed REST API
-
SRE vs. DevOps
-
Microservices Decoded: Unraveling the Benefits, Challenges, and Best Practices for APIs
-
How To Integrate Microsoft Team With Cypress Cloud
Comments