我必须生成安全令牌。这个令牌将被WebApi使用。我通过JavaScript文件请求Webapi。这是一个SPA应用程序。所以我的问题是,我可以生成下面提到的令牌而不使用Sql server响应吗?
The SQL syntax in Microsoft SQL Server to generate such a token is:
SELECT HASHBYTES('MD5', convert(varchar,getdate(),112) + Mysc@re4+)
OP的反馈:
我使用了angular-md5模块。这里是如何使用它。
<body ng-app="YOUR_APP" ng-controller="MainCtrl">
<img src="http://www.gravatar.com/avatar/{{ email | gravatar }}">
<input type="email" ng-model="email" placeholder="Email Address">
{{ message }}
</body>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script>
<script src="app/bower_components/angular-md5/angular-md5.js"></script>
<script>
angular.module('YOUR_APP', [
'angular-md5', // you may also use 'ngMd5' or 'gdi2290.md5'
'controllers'
]);
angular.module('controllers', [])
.controller('MainCtrl', ['$scope', 'md5', function($scope, md5) {
$scope.$watch('email' ,function() {
$scope.message = 'Your email Hash is: ' + md5.createHash($scope.email || '');
});
}]);
</script>
另一种方式:
你可以使用Crypto-JS库在JavaScript中生成MD5哈希值:
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/md5.js"></script>
<body>
<script>
var test = CryptoJS.MD5("string to hash");
alert(test);
</script>
</body>
</html>