什么是PKCS#5 PBKDF1在java中的算法名称?什么是替代CryptoPP :: PKCS5_PBKDF1在java? [英] What is the algorithm name for PKCS#5 PBKDF1 in java? what is substitute for CryptoPP::PKCS5_PBKDF1 in java?

查看:571
本文介绍了什么是PKCS#5 PBKDF1在java中的算法名称?什么是替代CryptoPP :: PKCS5_PBKDF1在java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个问题在使用加密。我使用AES



问题1:



我试图使用SecretKeyFactory类。我试图得到实例相关的PBKDF1 PKCS#5。我是新的密码学。我试过在线,但IAM不能找到任何这样的算法。支持它。我想要这样的东西。

  SecretKeyFactory factory = SecretKeyFactory.getInstance(PBKDF1Pkcs#5); 
KeySpec spec = new PBEKeySpec(password,salt,1,128);问题2:



上述两行代码是否与c ++中的下面几行代码做同样的事情

  :: PKCS5_PBKDF1< :: MD5> fn; 
fn.DeriveKey(key,CRYPTO :: MD5 :: DIGESTSIZE,0,key.getBytes(),salt.getBytes(),salt.size(),PBKDF1_ITERATIONS,time_in_seconds);

如果不能,可以有一些东西可以模仿上面的c ++代码行。



感谢

解决方案

strong>



SecretKeyFactory的Java 6 API文档


应用程序开发人员应参考其提供程序的文档其中的关键规范由generateSecret和getKeySpec方法支持。例如,由SunJCE提供者提供的DES秘密密钥工厂支持DESKeySpec作为DES密钥的透明表示,并且该提供商的用于三重DES密钥的秘密密钥工厂支持DESedeKeySpec作为三重DES密钥的透明表示。


如果我们查看用于PKCS的SunJCE提供程序文档,我们看到...


PBEWithMD5AndDES:基于密码的加密算法定义于:RSA实验室,PKCS#5:基于密码的加密标准,版本1.5,1993年11月。注意,该算法意味着CBC作为密码模式,PKCS5Padding填充方案,并且不能与任何其他加密模式或填充方案一起使用。


回答:问题2



在同一文档的使用基于密码的加密部分中,您将找到以下示例代码。请记住,示例代码使用静态盐,但安全实现将使用每次用户更改其密码时生成随机盐。

  PBEKeySpec pbeKeySpec; 
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;

// Salt
byte [] salt = {
(byte)0xc7,(byte)0x73,(byte)0x21,(byte)0x8c,
字节)0x7e,(字节)0xc8,(字节)0xee,(字节)0x99
};

//迭代计数
int count = 20;

//创建PBE参数集
pbeParamSpec = new PBEParameterSpec(salt,count);

//提示用户加密密码。
//将用户密码作为字符数组(使用上面的
//readPasswd方法),并将
//转换为SecretKey对象,使用PBE键
// factory。
System.out.print(输入加密密码:);
System.out.flush();
pbeKeySpec = new PBEKeySpec(readPasswd(System.in));
keyFac = SecretKeyFactory.getInstance(PBEWithMD5AndDES);
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

//创建PBE密码
密码pbeCipher = Cipher.getInstance(PBEWithMD5AndDES);

//用键和参数初始化PBE密码
pbeCipher.init(Cipher.ENCRYPT_MODE,pbeKey,pbeParamSpec);

//我们的明文
byte [] cleartext =这是另一个例子.getBytes();

//加密明文
byte [] ciphertext = pbeCipher.doFinal(cleartext);

其他算法



同样,从同一页。真的,我建议你阅读整个事情,因为它可能会回答其他问题你也有


PBEWith< digest> ; encryption>或PBEWith< prf> And< encryption> ;:与PKCS#5基于密码的加密一起使用的秘密密钥工厂,其中< digest>是消息摘要,< prf>是伪随机函数,并且<加密>是加密算法。实例:PBEWithMD5AndDES(PKCS#5,v 1.5)和PBEWithHmacSHA1AndDESede(PKCS#5,v 2.0)。注意:这两个只使用每个密码字符的低8位。



I have a couple of questions in using cryptography. I am using AES

Question 1:

I am trying to Use the SecretKeyFactory class in . I am trying to get instance related to PBKDF1 PKCS#5. I am new to cryptography. I tried online but Iam not able to find any such algorithm. Does support it. I want some thing like this.

    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF1Pkcs#5");
    KeySpec spec = new PBEKeySpec(password, salt, 1, 128);

Question 2:

Does the above two lines of code do the same thing as the below lines of code in c++

::PKCS5_PBKDF1 <::MD5> fn;
fn.DeriveKey(key, CRYPTO::MD5::DIGESTSIZE, 0, key.getBytes(), salt.getBytes(), salt.size(), PBKDF1_ITERATIONS,time_in_seconds);

If not can some one give some thing in which can mimic what the above lines of c++ code do.

Thanks

解决方案

Re: Question 1

Per the Java 6 API docs for SecretKeyFactory,

Application developers should refer to their provider's documentation to find out which key specifications are supported by the generateSecret and getKeySpec methods. For example, the DES secret-key factory supplied by the "SunJCE" provider supports DESKeySpec as a transparent representation of DES keys, and that provider's secret-key factory for Triple DES keys supports DESedeKeySpec as a transparent representation of Triple DES keys.

If we look at the SunJCE provider documentation for PKCS, we see...

PBEWithMD5AndDES: The password-based encryption algorithm as defined in: RSA Laboratories, "PKCS #5: Password-Based Encryption Standard," version 1.5, Nov 1993. Note that this algorithm implies CBC as the cipher mode and PKCS5Padding as the padding scheme and cannot be used with any other cipher modes or padding schemes.

Re: Question 2

In the same document, in the section Using Password-Based Encryption, you will find the following sample code. Keep in mind that the sample code uses a static salt, but a secure implementation would use generate a random salt each time the user changes their password.

PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;

// Salt
byte[] salt = {
    (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
    (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
};

// Iteration count
int count = 20;

// Create PBE parameter set
pbeParamSpec = new PBEParameterSpec(salt, count);

// Prompt user for encryption password.
// Collect user password as char array (using the
// "readPasswd" method from above), and convert
// it into a SecretKey object, using a PBE key
// factory.
System.out.print("Enter encryption password:  ");
System.out.flush();
pbeKeySpec = new PBEKeySpec(readPasswd(System.in));
keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

// Create PBE Cipher
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");

// Initialize PBE Cipher with key and parameters
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

// Our cleartext
byte[] cleartext = "This is another example".getBytes();

// Encrypt the cleartext
byte[] ciphertext = pbeCipher.doFinal(cleartext);

Other Algorithms

Again, from the same page. Really, I recommend you read through the whole thing, as it will probably answer other questions you have, as well

PBEWith<digest>And<encryption> or PBEWith<prf>And<encryption>: Secret-key factory for use with PKCS #5 password-based encryption, where <digest> is a message digest, <prf> is a pseudo-random function, and <encryption> is an encryption algorithm. Examples: PBEWithMD5AndDES (PKCS #5, v 1.5) and PBEWithHmacSHA1AndDESede (PKCS #5, v 2.0). Note: These both use only the low order 8 bits of each password character.

这篇关于什么是PKCS#5 PBKDF1在java中的算法名称?什么是替代CryptoPP :: PKCS5_PBKDF1在java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆