2016-07-28 48 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