2016-07-28 47 views
-1

我正在寻找一个基本的加密程序,我可以在js中使用。基本上,客户端需要将加密字符串传递给js库,并且js库需要解密字符串。所传递的信息是基本的,并且不是非常敏感,所以加密不需要太重。加密只需要基本。我想过使用base64编码程序,但这有点太基础且易于解密。有没有像base64编码的关键引入基本扭曲?在这种情况下你会使用什么类型的加密?寻找js的基本加密程序

+0

为什么加密的JS,每个人都可以看到使用这两种算法和密钥? –

回答

1

您可以使用类似AES-JS:

https://github.com/ricmoo/aes-js

这里是从页面使用的例子:

var key = aesjs.util.convertStringToBytes("Example128BitKey"); 

// The initialization vector, which must be 16 bytes 
var iv = aesjs.util.convertStringToBytes("IVMustBe16Bytes."); 

// Convert text to bytes 
var text = 'TextMustBe16Byte'; 
var textBytes = aesjs.util.convertStringToBytes(text); 

var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv); 
var encryptedBytes = aesCbc.encrypt(textBytes); 

// The cipher-block chaining mode of operation maintains internal 
// state, so to decrypt a new instance must be instantiated. 
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv); 
var decryptedBytes = aesCbc.decrypt(encryptedBytes); 

// Convert our bytes back into text 
var decryptedText = aesjs.util.convertBytesToString(decryptedBytes); 
console.log(decryptedText); 
// "TextMustBe16Byte" 
+1

此类问题无关紧要,不应回答。 – nicael

+0

谢谢约翰。由于美国用它来保​​护机密信息,AES相当沉重。更轻量级的东西可能会更好地满足我当前的需求,因为这个解决方案的期望之一是尽可能减少对响应时间的影响。 – user6604655