有没有人知道从任何长度的密码短语生成256位密钥值的方法?加密不能被加密,因为需要再次生成加密值并在数据库中进行比较.因此,每次加密时,值必须生成相同的加密字符串.
目前我正在使用一个32字符键来处理可能不正确的假设这是256位?
那么,我想要将"快速棕色狐狸"转换为合适的AES 256位密钥?
两个客户Alice和Bob使用服务器通过服务器登录和交换消息.登录时,他们都发送他们的公钥存储在服务器上.当Alice想要与Bob交谈时,她用Bob的公钥包含一个对称密钥,然后通过服务器将其发送给Bob.
如何确保服务器不会创建自己的公钥对并将其发送给Alice而不是Bob的公钥.这样,服务器将首先解密Alice发送的内容,并使用Bob的真实公钥再次对其进行加密.
谢谢
我有一个缓冲区,我正在添加一些纯文本.我想使用openssl AES加密来加密文本,然后将其解密,然后将其打印回屏幕.
代码正在运行,没有错误.
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string>
#include <openssl/aes.h>
using namespace std;
void main()
{
// Buffers
unsigned char inbuffer[1024];
unsigned char encryptedbuffer[1024];
unsigned char outbuffer[1024];
// CODE FOR ENCRYPTION
//--------------------
unsigned char oneKey[] = "abc";
AES_KEY key;
AES_set_encrypt_key(oneKey,128,&key);
AES_set_decrypt_key(oneKey,128,&key);
//--------------------
string straa("hello world\n");
memcpy((char*)inbuffer,straa.c_str(),13);
printf("%s",inbuffer);
//this prints out fine
AES_encrypt(inbuffer,encryptedbuffer,&key);
//printf("%s",encryptedbuffer);
//this is expected to pring out rubbish, so is commented
AES_decrypt(encryptedbuffer,outbuffer,&key);
printf("%s",outbuffer);
//this is not pringint "hello world"
getchar();
}
Run Code Online (Sandbox Code Playgroud)
我知道一旦放入新缓冲区"encryptedbuffer"和"outbuffer",它们不会以空终止"\ 0",但即便如此,通过打印出原始数据,我只是在垃圾后解密,在解密结束时,我假设\ 0也应该被解密,因此printf应该打印corectly.
任何人都知道如何使decyption工作? …
我正在开发Java加密应用程序.我想使用AES或DES等对称算法加密文件,并将secretKey存储在数据库中,以便将来解密文件.我想知道如何将SecretKey对象存储在数据库表中.我应该序列化关键对象吗?(secretKey是可串行的.)如何在数据库中存储序列化对象?我应该使用哪种MYSQL数据类型?
另一种解决方案是获取密钥的原始byte [],将其转换为base64并存储在数据库中.我以后可以将base64密钥解码为原始的Raw密钥,但问题在于将原始密钥转换为SecretKey对象.
任何帮助将受到高度赞赏.
最后,我在StackOverflow上发布了我的第一个问题.我现在使用这个网站多年了,我总能找到所有问题的答案:)
我正在实现一个基于官方Golang密码示例的文件加密后台守护程序:
func ExampleStreamReader() {
key := []byte("example key 1234")
inFile, err := os.Open("encrypted-file")
if err != nil {
panic(err)
}
defer inFile.Close()
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
// If the key is unique for each ciphertext, then it's ok to use a zero
// IV.
var iv [aes.BlockSize]byte
stream := cipher.NewOFB(block, iv[:])
outFile, err := os.OpenFile("decrypted-file", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
panic(err)
}
defer outFile.Close()
reader := &cipher.StreamReader{S: stream, …Run Code Online (Sandbox Code Playgroud) 这是我用来加密/解密数据的代码:
// Set the method
$method = 'AES-128-CBC';
// Set the encryption key
$encryption_key = 'myencryptionkey';
// Generet a random initialisation vector
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
// Define the date to be encrypted
$data = "Encrypt me, please!";
var_dump("Before encryption: $data");
// Encrypt the data
$encrypted = openssl_encrypt($data, $method, $encryption_key, 0, $iv);
var_dump("Encrypted: ${encrypted}");
// Append the vector at the end of the encrypted string
$encrypted = $encrypted . ':' . $iv;
// Explode the string using the `:` separator.
$parts …Run Code Online (Sandbox Code Playgroud) 我想询问有关使用初始化向量 (IV) 和对称加密算法密钥的最佳实践。
\n\n我想接受来自客户端的消息,对其进行加密并存储在后端。这将在一段时间内完成,稍后会有请求汇集消息并以可读的形式返回它们。
\n\n据我所知,在加密多个单独的消息时,密钥可以是相同的。IV 应该随着每个新的加密而改变。然而,这会导致问题,因为每条消息都需要不同的 IV 以便稍后解密。
\n\n我\xe2\x80\x99d想知道这是否是最好的方法。有没有办法避免在每条消息中存储 IV,从而简化加密/解密的整个过程?
\n在我的 ASP.NET WebForms 应用程序(该应用程序运行在 windows server 2008 R2、IIS 7.5 和 Runtime v4.0 集成模式应用程序池上,如果重要的话),我正在加密数据,将它放在 QueryString 上并使用System.Security.Cryptography.SymmetricAlgorithm类解密数据。但是我偶尔会在解密数据时遇到一些问题,我收到以下异常;
坏数据。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.Security.Cryptography.CryptographicException:错误数据。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。
堆栈跟踪:
[加密异常:错误数据。]
System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +33
System.Security.Cryptography.Utils._DecryptData(SafeKeyHandle hKey, Byte[] data, Int32 ib, Int32 cb, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode PaddingMode, Boolean fDone) +0
System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +313
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +33 Cryptography35.SymmetricEncryptionUtility.DecryptData(Byte[] data, String keyFile) 在 E:\Documents\@Library\Cryptography35\Cryptography35\SymmetricEncryptionUtility.cs:124 Cryptography35.SymmetricedQueryString.Symmetricly ..ctor(String encryptedData, String keyfilename, String algorithmname) in E:\Documents\@Library\Cryptography35\Cryptography35\SymmetricQueryString\SymmetriclyEncryptedQueryString.cs:67 WebForms.Web.Views.purchase_a.GetSymmetriclyEncryptedQueryString() 在 E:\Documents\ WebForms.Web\Views\purchase-a.aspx.cs:35 WebForms.Web.Views.purchase_a.Page_Load(Object sender, …
我想使用Android 密钥库对大型(多 MB)数据文件进行对称 AES 加密。
我已经编写了演示代码,可以使用密钥库加密/解密多 KB 文件,但是当文件大小变得太大时,它就会开始下降。此最大大小因设备而异,范围可以从 ~80KB 到 ~1MB。在我测试过的每台 Android-M 设备(包括模拟器)上,似乎都有一个最大大小,超过该大小后加密就会失败。
当它失败时,它会默默地失败——但是密文大小通常比应有的小很多(当然不能解密)。
由于它在多个设备上如此普遍,要么我做错了什么(可能!),要么对密钥库中可以加密的内容存在某种未记录的限制。
我在 Github 上编写了一个演示应用程序来显示问题(这里,特别是这个文件)。您可以运行应用程序 GUI 来手动解决问题,或者运行仪器测试来解决问题。
任何有关此问题的帮助或文档指示将不胜感激!
作为参考,我正在生成这样的对称密钥:
KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
keyGenerator.init(
new KeyGenParameterSpec.Builder(KEY_ALIAS, KeyProperties.PURPOSE_ENCRYPT|KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build()
);
SecretKey key = keyGenerator.generateKey();
SecretKeyFactory factory = SecretKeyFactory.getInstance(key.getAlgorithm(), "AndroidKeyStore");
KeyInfo keyInfo= (KeyInfo)factory.getKeySpec(key, KeyInfo.class);
logger.debug("isInsideSecureHardware: {}", keyInfo.isInsideSecureHardware());
Run Code Online (Sandbox Code Playgroud)
我这样加密:
KeyStore keyStore= KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
KeyStore.SecretKeyEntry keyEntry= (KeyStore.SecretKeyEntry)keyStore.getEntry(KEY_ALIAS, null);
Cipher cipher= getCipher();
cipher.init(Cipher.ENCRYPT_MODE, keyEntry.getSecretKey());
GCMParameterSpec params= cipher.getParameters().getParameterSpec(GCMParameterSpec.class);
ByteArrayOutputStream byteStream= new …Run Code Online (Sandbox Code Playgroud) 我花了令人尴尬的几个小时试图让 Libsodium.js 工作。
请参阅我的小提琴演示(以及下面粘贴的代码)。
我不断得到Error: wrong secret key for the given ciphertext。
我更喜欢将这个PHP 示例function simpleEncrypt($message, $key)复制到 Libsodium.js 中。
但作为一个初学者,我什至很高兴从 Libsodium.js 存储库中获取基本示例来工作。
有什么提示吗?
这是代码(也显示在工作小提琴中):
const _sodium = require("libsodium-wrappers");
const concatTypedArray = require("concat-typed-array");
(async () => {
await _sodium.ready;
const sodium = _sodium;
const utf8 = "utf-8";
const td = new TextDecoder(utf8);
const te = new TextEncoder(utf8);
const nonceBytes = sodium.crypto_secretbox_NONCEBYTES;
const macBytes = sodium.crypto_secretbox_MACBYTES;
let key = sodium.from_hex("724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed");
function encrypt_and_prepend_nonce(message, key) …Run Code Online (Sandbox Code Playgroud) encryption ×6
aes ×5
cryptography ×3
security ×2
.net ×1
android ×1
asp.net ×1
c# ×1
c++ ×1
go ×1
hash ×1
java ×1
javascript ×1
libsodium ×1
mysql ×1
openssl ×1
php ×1
php-openssl ×1