标签: encryption

使用 ECDH 和 Nodejs 加密解密秘密

这是nodejs文档示例:

const crypto = require('crypto');
const alice = crypto.createECDH('secp256k1');
const bob = crypto.createECDH('secp256k1');

// Note: This is a shortcut way to specify one of Alice's previous private
// keys. It would be unwise to use such a predictable private key in a real
// application.
alice.setPrivateKey(
  crypto.createHash('sha256').update('alice', 'utf8').digest()
);

// Bob uses a newly generated cryptographically strong
// pseudorandom key pair bob.generateKeys();

const alice_secret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
const bob_secret = bob.computeSecret(alice.getPublicKey(), null, 'hex');

// alice_secret and bob_secret should be …
Run Code Online (Sandbox Code Playgroud)

encryption cryptography node.js

5
推荐指数
1
解决办法
4931
查看次数

从视频流中下载加密的 TS 文件

在这篇文章之后,我通常使用浏览器的开发者控制台来查找 .ts 文件的 URL,然后使用 wget 下载它们来下载传输流 (.ts) 文件。之后我使用该ffmpeg -f concat方法将它们组合成一个mp4文件。

最近我遇到一个流视频网站,我使用相同的方法下载所有 .ts 文件。网站在这里。下载所有单独的 .ts 文件后,我使用 ffmprobe 检查文件格式,但意识到 ffmpeg/ffmprobe 无法理解 .ts 文件。虽然该网站使用 http(不是 https),但我认为流未加密,因此我尝试在十六进制编辑器中打开 .ts 文件,但我不知道它是什么格式(但它们看起来不像 zip/gz )。我的问题是:传输流是否加密?如果是,有办法解密吗?如果不?谁能指出我正确的方向,以便我可以让 ffmpeg 理解它们?

示例传输流(第一和第二)位于此处和此处,但链接可能稍后会过期。在这种情况下,您将需要在开发人员控制台中打开该站点以查找 .ts 文件的更新链接。

本站使用JW Player 8.0.0

encryption video ffmpeg

5
推荐指数
1
解决办法
2万
查看次数

libsodium PHP 在文件中存储私钥

我一直在 PHP 中使用 openssl 库来生成用于 RSA 加密的密钥对,并且发现在最新版本的 PHP 7.2 中,libsodium 现已集成。

我想更新到较新的库,并且可以生成密钥对。在 openssl 库中,我能够将密钥导出到加密的密钥文件中,以便存储在文件系统上。

libsodium 是如何实现这种等价的?

谢谢,

莱昂

php encryption rsa public-key-encryption libsodium

5
推荐指数
1
解决办法
1673
查看次数

将 Bouncy Castle 的 AsymmetryCipherKeyPair (RSA) 转换为 java.security.KeyPair

我正在尝试自动生成用于 E2E 测试的 CA 和证书。我从 Bouncy Castle 开始,成功生成了 CA 证书和机器证书。但是,现在我需要将 BC' 表示的 RSA 密钥对转换org.bouncycastle.crypto.AsymmetricCipherKeyPair为java.security.KeyPair. 我似乎找不到办法做到这一点。

java encryption bouncycastle jce

5
推荐指数
1
解决办法
1465
查看次数

CryptoJS 解密错误:格式错误的 UTF-8 数据

当我尝试解密 JSON 字符串时,Crypto-JS 库出现问题。

我的加密/解密函数:

function decrypt(data,key) {
return ((CryptoJS.AES.decrypt(data,key)).toString(CryptoJS.enc.Utf8));

}
function encrypt(data,key) {
return (CryptoJS.AES.encrypt(data, key).toString());

}
Run Code Online (Sandbox Code Playgroud)

我的程序按以下顺序运行:

ArrayWithObjects = [{test:1},{test:2}];
jsonStr = JSON.stringify(ArrayWithObjects);
encryptedString = encrypt(jsonStr,"testkey");
Run Code Online (Sandbox Code Playgroud)

然后将加密的字符串上传到网络服务器上的文件中。当用户访问另一个页面时,php 会回显文件的内容(加密字符串)。我已经验证该字符串是正确的。

var encryptedJsonStringFromServer = strFromServer;
var key = document.getElementById("keyInput").value
// Returns error:
decryptedJsonStringFromServer = decrypt(encryptedStringFromServer,key);
Run Code Online (Sandbox Code Playgroud)

如果我从控制台复制加密的字符串,并将其直接传递给解密函数,解密将按预期进行。

console.log(encryptedJsonStringFromServer);
decrypt("stringfromconsole","key") // Works as intented
Run Code Online (Sandbox Code Playgroud)

javascript encryption

5
推荐指数
0
解决办法
3204
查看次数

如何在php和android之间加密和解密数据

这些是我用来加密和解密基于 php 的服务器和 Android 应用程序之间的数据的类。

有时 php 解密类不起作用:

例如,当我在android中加密“abc”或“zdf”或“091360532561524369510”时,php类无法从android客户端解密加密数据。

你能检查一下这些课程吗? java类:

import java.security.NoSuchAlgorithmException;

import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class ApiCrypter
{
    private String iv= "0123456789012345";
    private String secretkey= "9876543210987654";
    private IvParameterSpec ivspec;
    private SecretKeySpec keyspec;
    private Cipher cipher;

    public ApiCrypter()
    {
        ivspec = new IvParameterSpec(iv.getBytes());
        keyspec = new SecretKeySpec(secretkey.getBytes(), "AES");

        try {
            cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        }
    }

    public byte[] encrypt(String text) throws Exception
    { …
Run Code Online (Sandbox Code Playgroud)

php java encryption

5
推荐指数
1
解决办法
4045
查看次数

Postgres 和 Node 之间的加密/解密

问题:我们必须加密某个表(Postgres)上的某个列。它必须在 SQL 查询和我们的 Nodejs/sequelize 应用程序层中可解密。加密可以发生在任一层中,但必须可以从任一层中解码。

\n\n

我遇到的问题(我确信这是用户错误)是,如果我在数据库中加密,我只能在数据库中解密,对于节点也是如此。

\n\n

我尝试过在 postgres 和node中使用PGP_SYM_ENCRYPTand 。我已经得到它的解密没有错误,但返回乱码。ENCRYPTcryptocrypto-js/aes

\n\n

到目前为止我尝试过的一些事情(测试键是thirtytwocharsthirtytwocharsplus):

\n\n
set() {\n  this.setDataValue('field', seq.cast(seq.fn('PGP_SYM_ENCRYPT', val, \n  config.AES_KEY), 'text'))\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这正确地写入了字段,使得 PGP_SYM_DECRYPT 能够解密它,但是(显然?)没有办法告诉 Sequelize 用函数调用包装字段名称,所以我觉得有很多额外的 js 是可以避免的

\n\n
const decipher = crypto.createDecipher('aes256', config.AES_KEY)\ndecipher.setAutoPadding(false);\nreturn decipher.update(new Buffer(this.getDataValue('field', 'binary'), 'binary', 'ascii')) + decipher.final('ascii')\n
Run Code Online (Sandbox Code Playgroud)\n\n

这将解码该字段,但返回乱码 ( \xef\xbf\xbdMq\xef\xbf\xbd\xef\xbf\xbd8Ya\xef\xbf\xbdb) 而不是值 ( test)

\n\n
aes.encrypt('test', config.AES_KEY)\naes.decrypt(field, config.AES_KEY).toString(CryptoJS.enc.Utf8)\n
Run Code Online (Sandbox Code Playgroud)\n\n

这可以很好地加密,解密也很好,但是 Postgres 在尝试解密时会出错(使用 或PGP_SYM_DECRYPT)DECRYPT。将结果字段转换::TEXT并粘贴到在线 AES …

encryption postgresql aes node.js

5
推荐指数
1
解决办法
5491
查看次数

如何在 pycryptodom 中使用 ECC 加密消息

我正在使用混合加密(RSA+AES),但长度很大,现在我想使用 ECC 而不是 RSA,但在 pycryptodom 中没有实现。这是我的 RSA 代码

def generate_keys():
    key = RSA.generate(1024)
    private_key = key.exportKey(format='PEM', pkcs=8, 
                  protection="scryptAndAES128-CBC")
    f = open("private_key.pem", "wb")
    f.write(private_key)
    public_key = key.publickey().exportKey('PEM')
    f = open("public_key.pem", "wb")
    f.write(public_key)
    f.close()

def encrypt(username, msg):
    #get the reciever's public key
    f = open("{}.pem".format(username)) # a.salama.pem
    recipient_key = RSA.import_key(f.read())
    f.close()

    # Encrypt the session key with the reciever's public RSA key
    cipher_rsa = PKCS1_OAEP.new(recipient_key)

    # Encrypt the data with the AES session key
    session_key = get_random_bytes(16)

    cipher_aes = AES.new(session_key, AES.MODE_EAX)
    ciphertext, …
Run Code Online (Sandbox Code Playgroud)

python encryption pycrypto

5
推荐指数
1
解决办法
9770
查看次数

如何在springboot中使用自定义类加载器

如何在 Spring Boot 中使用自定义类加载器加载 bean

\n\n

我需要加密 Spring Boot 项目。

\n\n

起初我尝试使用proguard,但失败了,因为 spring 使用大量 Annotations 并且它有DI。

\n\n

然后我尝试使用自定义类加载器。我想先加密我的类文件,然后使用我的自定义类加载器加载加密的类文件,然后解密它\xe3\x80\x82

\n\n

这是我的演示: https: //github.com/CaiBaohong/boot-by-custom-loader

\n\n

启动时失败:

\n\n
ConfigServletWebServerApplicationContext : \n  Exception encountered during context initialization - cancelling refresh attempt: \n    org.springframework.beans.factory.UnsatisfiedDependencyException: \n      Error creating bean with name \'methodValidationPostProcessor\' defined in class path resource \n        [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: \n          Unsatisfied dependency expressed through method \'methodValidationPostProcessor\' parameter 0; \n          nested exception is \n            org.springframework.beans.factory.CannotLoadBeanClassException: \n              Error loading class [com.abc.bootbycustomloader.controller.UserController] \n …
Run Code Online (Sandbox Code Playgroud)

encryption obfuscation spring classloader spring-boot

5
推荐指数
0
解决办法
3266
查看次数

如何在nodejs中加密和解密字符串/对象

我想加密一个对象然后解密它。加密效果很好,但解密失败。下面是我的代码:

加密扩展.js

const crypto = require("crypto")
const password = "shared_key"
const algorithm = "aes256"

export const encrypt = (text) => {
    if(!text) return ''
    const cipher = crypto.createCipher(algorithm, password);
    let crypted = cipher.update(text, 'utf-8', 'base64');
    crypted += cipher.final('base64');
    return crypted;
}

export const decrypt = (text) => {
    if(!text) return ''
    const decipher = crypto.createDecipher(algorithm, password);
    let decrypted = decipher.update(text, 'base64', 'utf-8');
    decrypted += decipher.final('utf-8');
    return decrypted;
}
Run Code Online (Sandbox Code Playgroud)

在我的test.js中,我有:

import {encrypt, decrypt} from './crypto_ext.js'
let test = {key1: …
Run Code Online (Sandbox Code Playgroud)

encryption node.js cryptojs node-crypto

5
推荐指数
1
解决办法
2万
查看次数