好的斯坦福Javascript加密库(SJCL)的例子? (JS加密) [英] Good Stanford Javascript Crypto Library (SJCL) examples? (JS cryptography)

查看:993
本文介绍了好的斯坦福Javascript加密库(SJCL)的例子? (JS加密)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在Javascript中执行客户端加密的方法(保留 http://www.matasano。 com / articles / javascript-cryptography / ),并找到 SJCL 。但我似乎无法找到良好的代码示例。任何指针?

I am looking at a way to do client-side cryptography in Javascript (keeping http://www.matasano.com/articles/javascript-cryptography/ in mind) and have found SJCL. But I seem unable to find good code examples for it. Any pointers?

推荐答案

我去年做了一个题为开发人员的JavaScript和Web加密技术指南​​,并且演示网站在线 https://jswebcrypto.azurewebsites.net/

I did a presentation last year titled Developer's Guide to JavaScript and Web Cryptography and have the demo site online at https://jswebcrypto.azurewebsites.net/

这包括OpenSSL命令行的简单哈希,HMAC,PBKDF2和AES示例(作为基线) SJCL CryptoJS Node.js加密,甚至 W3C Web加密API

This includes simple Hash, HMAC, PBKDF2 and AES examples for OpenSSL command line (as a baseline) SJCL, CryptoJS, Node.js Crypto, and even W3C Web Cryptography API

以下是SJCL示例:

Hash

var out = sjcl.hash.sha1.hash("The quick brown fox jumps over the lazy dog");
var hash = sjcl.codec.hex.fromBits(out)
// "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"

HMAC

var key = sjcl.codec.utf8String.toBits("key");
var out = (new sjcl.misc.hmac(key, sjcl.hash.sha256)).mac("The quick brown fox jumps over the lazy dog");
var hmac = sjcl.codec.hex.fromBits(out)
// "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"

PBKDF2

var hmacSHA1 = function (key) {
    var hasher = new sjcl.misc.hmac( key, sjcl.hash.sha1 );
    this.encrypt = function () {
        return hasher.encrypt.apply( hasher, arguments );
    };
};

var passwordSalt = sjcl.codec.hex.toBits( "cf7488cd1e48e84990f51b3f121e161318ba2098aa6c993ded1012c955d5a3e8" );
var derivedKey = sjcl.misc.pbkdf2( "password", passwordSalt, 100, 256, hmacSHA1 );
var hexKey = sjcl.codec.hex.fromBits( derivedKey );
// c12b2e03a08f3f0d23f3c4429c248c275a728814053a093835e803bc8e695b4e

注意:这需要您 sha1.js 以及sjcl.js。

Note: This requires you in include sha1.js in addition to sjcl.js.

这篇关于好的斯坦福Javascript加密库(SJCL)的例子? (JS加密)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆