MD5 Hashing for JavaScript

Gravatar requires the usage of MD5 hasing when it comes to pulling images from their website.  To accomplish this, I’ve implemented several MD5 plugins from different authors.

The plugin that integrated nicely (with no console errors) was JavaScript MD5.

To implement this on an Angular Component/Service:

import { Component } from '@angular/core';
var md5 = require("blueimp-md5");

@Component({
    selector: "app-some-component",
    template: ``
})
export class TestComponent {
    strUserEmail: string;

    /**
     * Returns a URL of the Gravatar image.
     * @return {string} - URL of user's image.
     */
     public getImage(): string {
         return "https://www.gravatar.com/avatar/" + md5(this.strUserEmail) + "?s=200";
     } // getImage()
}

Throughout my Angular service/component I can simply call md5().

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: