openssl 如何使用密钥,因为它采用任何大小的密钥(1 字节到任何大小)。在这里进入实际密钥的程序是什么..
openssl enc -d -des-ecb -in cipher.txt -out text.out -K '530343412312345445123345677812345678812324'
openssl 如何使用密钥,因为它采用任何大小的密钥(1 字节到任何大小)。在这里进入实际密钥的程序是什么..
openssl enc -d -des-ecb -in cipher.txt -out text.out -K '530343412312345445123345677812345678812324'
openssl 如何与密钥一起使用...程序是什么...
这取决于程序,但程序通常在整个库中是一致的。在您的示例中,您正在使用openssl dec
,因此您正在使用dec
子程序。源代码在<openssl dir>/apps/enc.c
(enc
并且dec
是enc.c
) 中可用。
以下是相关部分:
unsigned char key[EVP_MAX_KEY_LENGTH],iv[EVP_MAX_IV_LENGTH];
unsigned char salt[PKCS5_SALT_LEN];
...
char *hkey=NULL,*hiv=NULL,*hsalt = NULL;
to 的参数-K
存储在hkey
:
else if (strcmp(*argv,"-K") == 0)
{
if (--argc < 1) goto bad;
hkey= *(++argv);
}
然后,在第 580 行附近:
if ((hkey != NULL) && !set_hex(hkey,key,sizeof key))
{
/* Handle failure */
}
set_hex
如下所示,十六进制解码通过 传入的参数-K
。它通过memset
. 未使用的长度EVP_MAX_KEY_LENGTH
减去长度-K
参数(在十六进制解码之后)。
最后,在第 610 行附近:
if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, enc))
{
/* Handle failure */
}
注意:(-k
小k
)采用不同的代码路径并用于EVP_BytesToKey
派生密钥。
int set_hex(char *in, unsigned char *out, int size)
{
int i,n;
unsigned char j;
n=strlen(in);
if (n > (size*2))
{
BIO_printf(bio_err,"hex string is too long\n");
return(0);
}
memset(out,0,size);
for (i=0; i<n; i++)
{
j=(unsigned char)*in;
*(in++)='\0';
if (j == 0) break;
if ((j >= '0') && (j <= '9'))
j-='0';
else if ((j >= 'A') && (j <= 'F'))
j=j-'A'+10;
else if ((j >= 'a') && (j <= 'f'))
j=j-'a'+10;
else
{
BIO_printf(bio_err,"non-hex digit\n");
return(0);
}
if (i&1)
out[i/2]|=j;
else
out[i/2]=(j<<4);
}
return(1);
}
我对本案的观察得出以下结论: