<!DOCTYPE html>
<html ng-app="app">

  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
    <script src="script.js"></script>
    <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
    <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js"></script>
    <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script>
    <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha512.js"></script>
    <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
  </head>

  <body ng-controller="PruebaController">
    Contrase&ntilde;a:<input ng-model="password" />
    <br>
    El hash de la contrase&ntilde;a es:
    <br>
    {{getHash(password)}}
  </body>
</html>
var app=angular.module("app",[]);

app.constant("algoritmo","SHA-1");


function HashProvider() {
  var _algoritmo="";
  
  this.setAlgoritmo=function(algoritmo) {
    _algoritmo=algoritmo;
  };
  
  this.$get=function() {
    var hashFunction;
  
    if (_algoritmo==="MD5") {
      hashFunction=CryptoJS.MD5;
    } else  if (_algoritmo==="SHA-1") {
      hashFunction=CryptoJS.SHA1;
    } else  if (_algoritmo==="SHA-2-256") {
      hashFunction=CryptoJS.SHA256;
    } else  if (_algoritmo==="SHA-2-512") {
      hashFunction=CryptoJS.SHA512;
    } else {
      throw Error("El tipo de algoritmo no es vĂ¡lido:"+_algoritmo);
    }
  
    var hash=function(message) {
      var objHashResult=hashFunction(message);
      
      var strHashResult=objHashResult.toString(CryptoJS.enc.Base64);
    
      return strHashResult;
    }
  
    return hash;
  }
}

app.provider("hash",HashProvider);


app.config(["hashProvider","algoritmo",function(hashProvider,algoritmo) {
  hashProvider.setAlgoritmo(algoritmo);
}]);

app.controller("PruebaController",["$scope","hash",function($scope,hash) {
  $scope.password="s3cret";
  $scope.getHash=function(message) {
    var hashResult=hash(message);
    return hashResult;
  }
}]);


Ejemplo de provider