javascript RSA 和 AES 加密

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16383953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:26:05  来源:igfitidea点击:

RSA and AES encryption

javascriptencryption-asymmetricencryption-symmetricgoogle-chrome-app

提问by Cheetah

I am looking at the feasibility for using Chrome apps for the front end of some applications I am working on. (As an aside, if anyone has any thoughts on this - put it in the comments)

我正在研究在我正在开发的某些应用程序的前端使用 Chrome 应用程序的可行性。(顺便说一句,如果有人对此有任何想法-请在评论中提出)

I would be using chrome.socketand would want the connections to be secure so will need RSA and AES encryption that will be compatible with as many backend technology implementations as possible (C#, Java, ...). What I mean by this is the different modes, key-lengths, implementation-specific details...

我将使用chrome.socket并希望连接是安全的,因此需要 RSA 和 AES 加密,它们将与尽可能多的后端技术实现(C#、Java 等)兼容。我的意思是不同的模式、密钥长度、特定于实现的细节......

Now I have done a little searching myself and found https://code.google.com/p/crypto-js/for AES encryption. Is this still the accepted library to use, or is there another?

现在我自己做了一些搜索,找到了https://code.google.com/p/crypto-js/AES 加密。这仍然是公认的图书馆,还是有另一个?

...however, I couldn't find a library for RSA?

...但是,我找不到 RSA 库?

On the note of security, I don't foresee this being an issue as this is a Chrome extension,so the HTML/JavaScript is not being send over the internet, but is there any other security implication that I have missed?

关于安全性,我认为这不会成为一个问题,因为这是一个 Chrome 扩展程序,因此 HTML/JavaScript 不会通过互联网发送,但是我是否遗漏了其他任何安全隐患?

回答by Don Rhummy

You could try using this:

你可以尝试使用这个:

Stanford Javascript Crypto Library: http://crypto.stanford.edu/sjcl/

斯坦福 Javascript 加密库:http: //crypto.stanford.edu/sjcl/

SJCL is secure. It uses the industry-standard AES algorithm at 128, 192 or 256 bits; the SHA256 hash function; the HMAC authentication code; the PBKDF2 password strengthener; and the CCM and OCB authenticated-encryption modes.

SJCL 是安全的。它使用 128、192 或 256 位的行业标准 AES 算法;SHA256 哈希函数;HMAC认证码;PBKDF2 密码强化程序;以及 CCM 和 OCB 认证加密模式。

Check the API here: http://bitwiseshiftleft.github.io/sjcl/doc/

在此处检查 API:http: //bitwiseshiftleft.github.io/sjcl/doc/

Stanford also has a page showing RSA (among others) encryption in Javascript: http://www-cs-students.stanford.edu/~tjw/jsbn/

斯坦福大学还有一个页面显示了 Javascript 中的 RSA(以及其他)加密:http: //www-cs-students.stanford.edu/~tjw/jsbn/

RSA and ECC in JavaScript:

The jsbn library is a fast, portable implementation of large-number math in pure JavaScript, enabling public-key crypto and other applications on desktop and mobile browsers.

JavaScript 中的 RSA 和 ECC:

jsbn 库是纯 JavaScript 中大量数学的快速、可移植实现,支持桌面和移动浏览器上的公钥加密和其他应用程序。

They also state it is 100% interoperable with openssland have instructions on how you can confirm this.

他们还声明它可以 100% 互操作,openssl并有关于如何确认这一点的说明。

You could also try CryptoJS: https://code.google.com/p/crypto-js/

您也可以尝试 CryptoJS:https: //code.google.com/p/crypto-js/

CryptoJS is a growing collection of standard and secure cryptographic algorithms implemented in JavaScript using best practices and patterns. They are fast, and they have a consistent and simple interface.

CryptoJS 是使用最佳实践和模式在 JavaScript 中实现的标准和安全加密算法的不断增长的集合。它们速度很快,并且具有一致且简单的界面。

回答by dlongley

It seems like you might prefer to have a full TLS implementation here. You should be able to wrap chrome.socket with a TLS wrapper using forge (a JavaScript implementation of TLS):

看起来您可能更喜欢在这里有一个完整的 TLS 实现。您应该能够使用伪造(TLS 的 JavaScript 实现)使用 TLS 包装器包装 chrome.socket:

https://github.com/digitalbazaar/forge

https://github.com/digitalbazaar/forge

回答by Lo?c Faure-Lacroix

I'm pointing out some of my work I did for university, it's probably full of bugs and could be done in a better way. It's quite fast and works well with big keys. It's possible to use RSA with keys with n Bits.

我指出了我为大学所做的一些工作,它可能充满了错误,可以以更好的方式完成。它非常快,适用于大键。可以将 RSA 与 n 位的密钥一起使用。

Check the tests if you need to understand how it works. Any bug or improvement would be appreciated though.

如果您需要了解它是如何工作的,请检查测试。任何错误或改进将不胜感激。

Note, you might have to search a little because there is more than just RSA.

请注意,您可能需要进行一些搜索,因为不仅仅是 RSA。

https://github.com/llacroix/rsa-js

https://github.com/llacroix/rsa-js