标签: encryption

是否可以在 JDK 1.7 上使用 GCM 和 BC?

我正在尝试使用任何 AES GCM 变体进行 TLS 连接,根据我在文档中的理解,这应该是可能的,但我收到此错误:

Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1989)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1096)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1342)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1369)
Run Code Online (Sandbox Code Playgroud)

问题是我尝试连接的服务器只接受这些密码:

TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_RSA_WITH_AES_256_GCM_SHA384
TLS_RSA_WITH_AES_128_GCM_SHA256
Run Code Online (Sandbox Code Playgroud)

我无法在此处发布我尝试连接的服务器,但我尝试在 github 存储库上复制该问题。我找不到只接受这些密码套件的服务器,这就是为什么我的 repo 因另一个错误而失败。

git clone https://github.com/andreicristianpetcu/gcm_with_bc_onjdk17
cd gcm_with_bc_onjdk17
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre" mvn clean install
Run Code Online (Sandbox Code Playgroud)

基本上这是来自 GitHub 的代码

    package com.github.gcm_with_bc_onjdk17;

    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.conn.ssl.NoopHostnameVerifier;
    import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClients;
    import org.apache.http.ssl.SSLContexts;

    import javax.crypto.Cipher;
    import javax.crypto.NoSuchPaddingException;
    import javax.net.ssl.SSLContext;
    import java.io.IOException;
    import java.security.KeyManagementException;
    import java.security.NoSuchAlgorithmException;
    import java.security.NoSuchProviderException;
    import …
Run Code Online (Sandbox Code Playgroud)

encryption ssl bouncycastle java-7 aes-gcm

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

使用golang解密用php openssl_encrypt加密的文件

首先。我在这里如履薄冰!

我有一个从 php 获得的加密文件。我正在尝试用 golang 解密它。

php 应用程序使用公共 RSA 密钥来加密用于使用 aes-256-cbc 加密的密钥。

我已经创建了一些概念验证代码,但我做对了。尽管 key 和 iv 在双方看起来都是正确的,但有些东西不是。结果只是垃圾。我怀疑一些编码不匹配(期望 base64,获取字符串字节......某事)或者我误解了一些概念。

加密:

<?php

$cipher = "AES-256-CBC";
$ivLength = openssl_cipher_iv_length($cipher="AES-256-CBC");
echo "iv len: " . $ivLength . "\n";
$iv = openssl_random_pseudo_bytes($ivLength);
$key = "1234567890abcdef";

$ciphertext = openssl_encrypt("hello world", $cipher, $key, 0, $iv);

$publicKey = openssl_pkey_get_public(file_get_contents("some-public-key.pub"));
if (!$publicKey) {
   die("OpenSSL: Unable to get public key for encryption. Is the location correct? Does this key require a password?");
}

$ok = openssl_public_encrypt($key, $encryptedKey, $publicKey);
if (!$ok) …
Run Code Online (Sandbox Code Playgroud)

php encryption openssl go

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

CngKey 为机器密钥分配权限

我创建了一个机器范围的 CngKey (MachineKey=true),但我的应用程序无法访问它。

如何分配权限以便我的应用程序池可以访问密钥?最好是务实的,这样我就可以将它构建到安装程序中。

Powershell 创建脚本:

[System.Security.Cryptography.CngKeyCreationParameters] $cngKeyParameter =  [System.Security.Cryptography.CngKeyCreationParameters]::new()
    $cngKeyParameter.KeyUsage = [System.Security.Cryptography.CngKeyUsages]::AllUsages
    $cngKeyParameter.ExportPolicy = [System.Security.Cryptography.CngExportPolicies]::AllowPlaintextExport

    $cngKeyParameter.Provider = [System.Security.Cryptography.CngProvider]::MicrosoftSoftwareKeyStorageProvider
    $cngKeyParameter.UIPolicy = [System.Security.Cryptography.CngUIPolicy]::new([System.Security.Cryptography.CngUIProtectionLevels]::None)
    $cngKeyParameter.KeyCreationOptions = [System.Security.Cryptography.CngKeyCreationOptions]::MachineKey

    #Create Cng Property for Length, set its value and add it to Cng Key Parameter
    [System.Security.Cryptography.CngProperty] $cngProperty = [System.Security.Cryptography.CngProperty]::new($cngPropertyName, [System.BitConverter]::GetBytes(2048), [System.Security.Cryptography.CngPropertyOptions]::None)
    $cngKeyParameter.Parameters.Add($cngProperty)

    #Create Cng Key for given $keyName using Rsa Algorithm
    [System.Security.Cryptography.CngKey] $key = [System.Security.Cryptography.CngKey]::Create([System.Security.Cryptography.CngAlgorithm]::Rsa, "MyKey", $cngKeyParameter)
Run Code Online (Sandbox Code Playgroud)

security encryption cng

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

HMAC解密

我编码了 HMAC 解密。我多次尝试解密输出。

这是我的代码

package javaapplication_HMAC;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import java.util.Formatter;

public class Encryption {

    public void Encryption_Base64(String x,String y){
     String message = x;
        String key = y;
        String algorithm = "HmacSHA1";  
        try {
            Mac sha256_hmac = Mac.getInstance(algorithm);
            SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), algorithm);
             sha256_hmac.init(secret_key);
            String hash = Base64.encode(sha256_hmac.doFinal(message.getBytes("UTF-8")));
            System.out.println(hash);
        } catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) {
            e.printStackTrace();
        }    
    }

    public static void main(String args[]) {
        Encryption encryption_base64 = …
Run Code Online (Sandbox Code Playgroud)

java encryption base64 hmac

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

Node.js AES 解密 Base64 字符串

我正在解密Firebase正在发送到Firebase function.

我对加密很陌生。但是我正在使用AES-256, 静态IV(我知道没有随机 iv 不是最好的解决方案)。

但我在两者上都得到了正确的结果Android,iOS但在node.js.

消息是 Base64 编码的

这是我的代码:

const crypto = require('crypto');
const cryptoKey = "MyEncryptionKey1MyEncryptionKey1";
const text = "Cidor8Ph7pZqPw0x2AwIKw=="

let messageToDecrypt = new Buffer(text, "utf8")
let key = new Buffer(cryptoKey, "utf8");
var decipher = crypto.createCipheriv('aes-256-cbc', key, iv);
var decoded = decipher.update(messageToDecrypt,'base64','utf-8');
decoded += decipher.final('utf-8');
text = decoded
console.log(decoded
Run Code Online (Sandbox Code Playgroud)

代码编译并运行,但它给了我一个看起来类似于这个的笨拙的答案 ??C?p?-Q?)?1H&?8pD}5?i????g

关于如何改进此代码的任何想法?

javascript encryption node.js google-cloud-functions

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

“原因:DHPublicKey 不符合算法约束”是什么意思?

当我想连接到另一台机器时,我看到了这个错误:

严重:无法创建连接 XXXXX:XXXXX 建立到主机和端口的套接字时出错:XXXXX:XXXXX。原因:DHPublicKey 不符合算法约束

这是什么原因?

java security encryption

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

ASP.NET Core Data Protection 跨平台加密提供程序

我正在尝试将 asp.net 核心 DataProtectionProvider 与支持服务器场的单个数据库一起使用。我为商店实现了一个 IXmlRepository,我成功地向运行我的服务器的两台机器提供了相同的证书。我确认我正在以相同的顺序使用相同用途的字符串,但是当我尝试从机器 a 编码的机器 ba 字符串中取消保护时,我得到了一个通用的 CryptographicException。

如果机器 a 和机器 b 是 2 个不同的操作系统,这有关系吗?(Linux 与 Windows 服务器)

我得到的例外是:

{System.Security.Cryptography.CryptographicException:抛出了“System.Security.Cryptography.CryptographicException”类型的异常。在 Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.ThrowExceptionForBCryptStatusImpl(Int32 ntstatus) 在 Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.ThrowExceptionForBCryptStatus(Int32 ntstatus) 在 Microsoft.AspNetCore.DataProtection.Cng.Gcm. pbAdditionalAuthenticatedData, UInt32 cbAdditionalAuthenticatedData)
在 Microsoft.AspNetCore.DataProtection.Cng.Internal.CngAuthenticatedEncryptorBase.Decrypt(ArraySegment)1 ciphertext, ArraySegment1 个额外的 AuthenticatedData) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector,[Dangerer , Boolean& wasRevoked) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData) 在 Microsoft.AspNetCore.DataProtection.DataProtectionCommonExtensions.Unprotect(IDataProtectorprotector, String protectedData)

.net encryption .net-core asp.net-core

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

在 MySQL 数据库上存储密码:哈希与加密?

我一直在阅读在 MySQL 数据库上存储敏感数据时使用散列与加密的利弊,而赞成散列或加密的人的双方争论只会让我对使用哪个感到困惑和不确定.

哈希:

"INSERT INTO users (`id`,`username`,`password`) VALUES("Bob",SHA2("password1234"));"
Run Code Online (Sandbox Code Playgroud)

缺点:

  • 已弃用

  • 彩虹桌

加密:

"INSERT INTO users (`id`, `username`, `password`) VALUES ("Bob", aes_encrypt("password1234", "key1234"))";
Run Code Online (Sandbox Code Playgroud)

缺点:

  • 可能不适用于某些归类类型

  • 密钥可能被泄露

  • 彩虹桌

那么在提供安全性和性能(从数据库中快速读取和检索)方面,哪个更理想?(在大约 1,000 - 5,000 行的表格中)。

mysql database encryption hash password-protection

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

Java AES GCM 标签不匹配

我有 Java AES GCM 加密问题。我已按照此页面上的说明生成以下代码:

package aes;

import java.nio.ByteBuffer;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES {
    private Cipher encryptCipher;
    private Cipher decryptCipher;
    private byte[] key;
    private int keyLength;
    private SecretKeySpec keySpec;
    private SecureRandom random;

    public AES(String key) {
        try {
            this.key = key.getBytes();
            this.keyLength = this.key.length*8; // key length in bits
            this.keySpec = new SecretKeySpec(this.key, "AES");
            this.encryptCipher = Cipher.getInstance("AES/GCM/NoPadding");
            this.decryptCipher = Cipher.getInstance("AES/GCM/NoPadding");
            this.random = SecureRandom.getInstance("SHA1PRNG");
        }
        catch (Exception e) {
            System.err.println(e.getMessage());
        }
    } …
Run Code Online (Sandbox Code Playgroud)

java encryption aes aes-gcm

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

加密列上的模式匹配

即使在 SQL Server 2019 版本中,我也无法对加密列进行模式匹配。

SQL Server 2019

加密前

select * 
from messageencryption;     
Run Code Online (Sandbox Code Playgroud)

输出:

id    msgcode   msg      
-------------------------------------------
1      AA56B    this is a text message     
2      AA56C    this is a text123 message    
3      AA56D    EXTENDED BOOTCAMP      
4      AA56E    extended bootcamp       
5      AA56J    advance happy new year       
6      AA56K    oneteam       
7      AA56L    cricket team consists of 11 players       
8      AA56M    indian cricket team      

select * 
from messageencryption 
where msg like '%team%';       
Run Code Online (Sandbox Code Playgroud)

输出:

id   msgcode   msg              
----------------------------
6    AA56K     onesmallteam                   
7    AA56L …
Run Code Online (Sandbox Code Playgroud)

sql-server encryption always-encrypted

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