DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

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

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
  1. DZone
  2. Data Engineering
  3. Data
  4. Android Snippet: MAking a md5 hash from a string in Java

Android Snippet: MAking a md5 hash from a string in Java

Mark Mooibroek user avatar by
Mark Mooibroek
·
Apr. 30, 11 · News
Like (0)
Save
Tweet
Share
25.06K Views

Join the DZone community and get the full member experience.

Join For Free
Security 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)Android tutorial
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

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: