Tag: encryption

Java和Node之间的encryption不一致

我试图在Node.js中复制一个基于Java的encryptionscheme,但不幸的是我得到了不一致的结果。 这是Java方法: private Transfer encrypt(byte[] salt, String ticketNumber, String data) throws Exception { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(ticketNumber.toCharArray(), salt, 1000, 128); SecretKey tmp = factory.generateSecret(spec); SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES"); String encoded = java.util.Base64.getEncoder().encodeToString(secret.getEncoded()); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] iv ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; IvParameterSpec ips = new IvParameterSpec(iv); cipher.init(Cipher.ENCRYPT_MODE, secret, ips); AlgorithmParameters […]

使用JavaScript扩展DESKey

我在Node.js中实现一个协议 该协议在CBC模式下使用3DESencryption,没关系。 但要encryption/解密,我需要扩大/扩大14个字节的DES密钥到16个字节只是添加奇偶校验位。 但。 我坚持使用JavaScript / Node.js。 我有一些使用C和Python的实现,任何人都可以帮助我使用JavaScript / Node.js(我的试用版下面)做同样的事情? uint8 *des_key_spread(uint8 *normal){ static uint8 spread[16]; spread[ 0] = normal[ 0] & 0xfe; spread[ 1] = ((normal[ 0] << 7) | (normal[ 1] >> 1)) & 0xfe; spread[ 2] = ((normal[ 1] << 6) | (normal[ 2] >> 2)) & 0xfe; spread[ 3] = ((normal[ […]

在Unity3D C#中encryptionstring,通过HTTP GET请求作为URL参数发送,在node.js服务器中解密

我在Unity WebGL中使用了一种非常有效的泡泡糖和胶带解决scheme来处理一个小型街机游戏的在线排行榜。 目前,游戏客户端使用两个参数?name=NAME&score=111111发送HTTP GET请求。 虽然url不会正常显示给普通玩家,但显然通过浏览器开发工具很容易find和利用。 我的解决scheme是以某种方式用游戏客户端和服务器专用的密钥encryption得分string,如果提交的string没有成功解密,服务器将拒绝得分。 然而,我对密码学的理解是绝对零度的,而且我的很多尝试Google解决scheme和从许多结果中调整代码都是徒劳的。 我不知道要使用哪种algorithm,我的密钥是否实际可用,以及为什么每个东西都不起作用。 我不知道如何轻易地阻止这个排行榜提交虚假的分数,这是我能想到的最可行的解决scheme。 我怎样才能解密在Unity端的短string,通过URL传递,然后解密从node.js结束,并根据是否成功解密执行特定的代码?

如何在Python中encryption和在Javascript中解密?

我可以使用Python或JavaScriptencryption/解密,但将由Python生成的encryption数据传递给我的JavaScript代码失败。 base64编码/解码跨语言工作,以便Python上的基本编码和JavaScript上的解码检索原始的encryptionstring。 testingfunction之外,我没有使用Python解密或JavaScriptencryption,但他们在这里是为了完整性,因为一些读者错过了文本说他们存在。 在Python 2中: import base64 from pyaes import AESModeOfOperationCTR SECRET_KEY = "This_key_for_demo_purposes_only!" def encrypt(raw_data, key=SECRET_KEY): aes = AESModeOfOperationCTR(key) encrypted_data = aes.encrypt(raw_data) base64_encrypted_data = base64.b64encode(encrypted_data) return base64_encrypted_data def decrypt(base64_encrypted_data, key=SECRET_KEY): encrypted_data = base64.b64decode(base64_encrypted_data) aes = AESModeOfOperationCTR(key) decrypted = aes.decrypt(encrypted_data) return decrypted 在JavaScript(运行服务器端,在Parse.com云代码): var Buffer = require('buffer').Buffer; var Crypto = require('crypto'); encrypt: function(raw) { var […]

从JavaScript创build一个PEM文件看起来不同于Java导致签名validation失败

我试图validation与公钥RSA签名的SHA1,我已经写了下面的Java代码完美的作品,但是JavaScript无法validation它何时使用相同的模数和由crypto或ursa创build的指数。 虽然如果我用它对Java创build的Pem文件它的作品。 任何想法或build议的Java代码转换为JavaScript的最佳方式? JAVA: import java.math.BigInteger; import java.security.KeyFactory; import java.security.Signature; import java.security.interfaces.RSAPublicKey; import java.security.spec.RSAPublicKeySpec; import java.util.Base64; public class Verify { static public Boolean verifySignature(String modulus, String exponent , String encodedMsg, String encodedSignature, String signatureAlgorithm) throws Exception { try { RSAPublicKeySpec senderPublicKeySpec = new RSAPublicKeySpec( new BigInteger(modulus, 16), new BigInteger(exponent, 16) ); RSAPublicKey rsaPublicKey = (RSAPublicKey) […]

Node.js让我们在Chrome中encryptionfile upload错误

在Node.js(Sails.js)应用程序中启用了SSL,我无法上传大文件。 我的上传工作正常,没有SSL。 目前,在configurationSSL的情况下,我只能上传非常小的文件。 我正在使用“让我们encryption”SSL证书。 我也意识到,这种行为只能在谷歌浏览器(版本47.0.2526.106米),如果我上传超过100Kb的文件,它会返回我302 Moved Temporarily 。 Firefox似乎正在做的很好。

Node.js'crypto.createSign()的有效algorithminputstring

我正在使用一个项目的节点的encryption签名,并一直在试图考虑各种algorithm的起伏。 crypto.createSign()的描述如下所示: 创build并返回使用给定algorithm的Sign对象。 在最近的OpenSSL版本中, openssl list-public-key-algorithms将显示可用的签名algorithm。 一个例子是“RSA-SHA256”。 不幸的是,“RSA-SHA256”不是openssl list-public-key-algorithms的输出值之一(如下所示)。 那么这个函数的有效值是什么,或者如何从下面的列表中提取出来? OpenSSL list result: Name: OpenSSL RSA method Type: Builtin Algorithm OID: rsaEncryption PEM string: RSA Name: rsa Type: Alias to rsaEncryption Name: OpenSSL PKCS#3 DH method Type: Builtin Algorithm OID: dhKeyAgreement PEM string: DH Name: dsaWithSHA Type: Alias to dsaEncryption Name: dsaEncryption-old Type: Alias to […]

在浏览器中通过WebCryptoAPI生成ECDH密钥,而不是浏览器化的节点密码模块

我有一个非常小的节点脚本来创build一个公钥/私钥有没有办法在客户端做到这一点,而不必浏览孔encryption模块? var crypto = require('crypto'); var userCurve = crypto.createECDH('prime256v1'); var userPublicKey = userCurve.generateKeys() var userPrivateKey = userCurve.getPrivateKey(); 到目前为止,我已经尝试过: // https://github.com/diafygi/webcrypto-examples#ecdh—generatekey window.crypto.subtle.generateKey( { name: "ECDH", namedCurve: "P-256", //can be "P-256", "P-384", or "P-521" }, true, //whether the key is extractable (ie can be used in exportKey) ["deriveKey", "deriveBits"] //can be any combination of "deriveKey" and "deriveBits" […]

NodeJS 6encryption在贬低消息抱怨摘要?

我试图在我的NodeJS应用程序中使用本机encryption模块,但我不断收到弃用消息: (node:26)DeprecationWarning:不指定摘要的crypto.pbkdf2已被弃用。 请指定一个摘要 我知道这是由于一个变化集,预计摘要向前移动: https : //github.com/nodejs/node/pull/4047 但是,从我所看到的,我的代码完全按照文档中概述的语法。 任何人看到我在这里做错了吗? function verify (password, expected, callback) { const combined = Buffer.from(expected, 'base64') const saltBytes = combined.readUInt32BE(0) const hashBytes = combined.length – saltBytes – 8 const iterations = combined.readUInt32BE(4) const salt = combined.slice(8, saltBytes + 8) const hash = combined.toString('binary', saltBytes + 8) return crypto.pbkdf2(password, salt, iterations, hashBytes, […]

使用JavaScript中的PFX文件的RSA私钥创buildJWT(NodeJS)

我试图从PFX文件创build一个RSA私钥,我可以使用它来创build一个JWT。 我不太了解事物的安全性,所以很难find合适的库来使用。 我有一个提供的PFX,我需要使用它来encryptionJSON有效载荷(在一个Node应用程序中),然后将其发送到第三方(Java)后端服务器进行解密。 任何示例代码来做到这一点将不胜感激。