如何解密pbkdf2加密文本,不知道IV [英] How to decrypt pbkdf2 encrypted text without knowing the IV
问题描述
我有盐值,迭代次数和密钥长度。但是我没有初始化向量(IV)值,我该怎么去解密呢?我也有秘密密钥。
暂时我正在使用大小为16字节的随机IV值。
但是我仍然无法正确解密该值。
任何人都可以帮忙,因为我很久以来一直呆在这里?
以下是给了我。
salt = EW0h0yUcDX72WU9UiKiCwDpXsJg =,迭代= 128,Keylenght = 16。
MasterKeyName = Passphrase1,MACMethod ALGO = HMAC-SHA1,麦基= JQ / NdikC7AZf0Z + HEL5NrCICV8XW + ttzl / 8687hVGHceoyJAaFws + 111plQH 6Mlg 加密KAE = pM7VB / KomPjq2cKaxPr5cKT1tUZN5tGMI + u1XKJTG1la + ThraPpLKlL2plKk6vQE 和valuemac =LBU + 9OcLArnj6mS7KYOKDa4zRU0 =。
秘密密钥=xxxxxxxxxxx。
下面是我用来解密的代码。
SecretKeyFactory factory = SecretKeyFactory.getInstance(PBKDF2WithHmacSHA1);
KeySpec spec = new PBEKeySpec(secretkey.toCharArray(),salt,iterationCount,keyStrength);
SecretKey tmp = factory.generateSecret(spec);
key = new SecretKeySpec(tmp.getEncoded(),AES);
dcipher = Cipher.getInstance(AES / CBC / PKCS5Padding);
AlgorithmParameters params = dcipher.getParameters();
iv =0000000000000000.getBytes();
System.out.println(IV+ new sun.misc.BASE64Encoder()。encodeBuffer(iv));
dcipher.init(Cipher.DECRYPT_MODE,key,new IvParameterSpec(iv));
byte [] decryptptedData = new sun.misc.BASE64Decoder()。decodeBuffer(base64EncryptedData);
byte [] utf8 = dcipher.doFinal(decryptptedData);
您无法解密第一个 CBC加密密文块,如果你不知道IV。
然而,您不太可能可以检索IV值:
- 通常,从PBKDF生成的关键字节之后,IV值是16字节检索;
- 通常将IV置于密文之前,导致一个解密前的全部明文之前的垃圾;
- 不安全,但IV也被省略或设置为常数值,全零IV是最常见的(这是相同的CBC模式不使用任何IV。)
I am trying to decrypt an encrypted text. I have the salt value, iteration count and key length. But i don't have the initialization vector (IV) value, how can i go about and decrypt this. I also have secret key.
For time being I am using some random IV value whose size is 16 bytes. But still i am not able to decrypt the value properly. Can anyone please help as i am stuck with this for a long time?
Below are the values which were given to me.
salt= EW0h0yUcDX72WU9UiKiCwDpXsJg=, Iteration=128,Keylenght=16.
MasterKeyName="Passphrase1", MACMethod algo = hmac-sha1, MACKey="jq/NdikC7AZf0Z+HEL5NrCICV8XW+ttzl/8687hVGHceoyJAaFws+111plQH 6Mlg" encrypted kae = "pM7VB/KomPjq2cKaxPr5cKT1tUZN5tGMI+u1XKJTG1la+ThraPpLKlL2plKk6vQE" and valuemac="lbu+9OcLArnj6mS7KYOKDa4zRU0=".
Secret key = "xxxxxxxxxxx".
Below is the code which I am using to decrypt.
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(secretkey.toCharArray(), salt, iterationCount, keyStrength);
SecretKey tmp = factory.generateSecret(spec);
key = new SecretKeySpec(tmp.getEncoded(), "AES");
dcipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
AlgorithmParameters params = dcipher.getParameters();
iv = "0000000000000000".getBytes();
System.out.println("IV " + new sun.misc.BASE64Encoder().encodeBuffer(iv));
dcipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
byte[] decryptedData = new sun.misc.BASE64Decoder().decodeBuffer(base64EncryptedData);
byte[] utf8 = dcipher.doFinal(decryptedData);
You cannot decrypt the first block of CBC encrypted ciphertext if you don't know the IV.
It is however not unlikely that you can retrieve the IV value:
- often the IV value is 16 bytes retrieved after the key bytes) generated from the PBKDF;
- the IV is often prepended to the ciphertext, resulting in one block of garbage before the full plaintext during decryption;
- not secure but the IV is also left out or set to a constant value, with an all-zero IV being the most common (this is identical in CBC mode to not using any IV.)
这篇关于如何解密pbkdf2加密文本,不知道IV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!