1

I am writing piece of code that decrypts data in java, which is encrypted in some C++ code using [poco lib] (http://pocoproject.org/docs/).

C++ code is similar as shown below:

std::string password = "secret";
std::string salt("asdff8723lasdf(**923412");
CipherKey key("aes-256", password, salt);

Also with iteration count of 2k.

DEFAULT_ITERATION_COUNT = 2000

How do I create that same key in java to decrypt the data? What is equivalent code in java?

I am trying something like this,

    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    char[] passowrd = "secret".toCharArray();
    byte[] salt = "asdff8723lasdf(**923412".getBytes();

    KeySpec spec = new PBEKeySpec(passowrd,salt, 2000);
    SecretKey tmp = factory.generateSecret(spec);
    SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");

But, it doesn't works. Gives me no such algorithm found exception. Which algorithm should I use? Do I need to know something more to decrypt?

UPDATE
I have added bounty castle to my security provider as pointed out by user2504380

Community
  • 1
  • 1
Shashank
  • 416
  • 5
  • 16
  • What is the output of Security.getProviders() ? – user2504380 Oct 06 '14 at 08:54
  • This is the output :SUN version 1.7 SunRsaSign version 1.7 SunEC version 1.7 SunJSSE version 1.7 SunJCE version 1.7 SunJGSS version 1.7 SunSASL version 1.7 XMLDSig version 1.0 SunPCSC version 1.7 SunMSCAPI version 1.7 – Shashank Oct 06 '14 at 09:14
  • Dont you miss the BouncyCastle Security Provider there? – user2504380 Oct 06 '14 at 09:25
  • In providers? nope that's complete list. – Shashank Oct 06 '14 at 09:27
  • No, i mean, i dont see bouncycastle, habe you installed it? Because you need to have, as far, as i know from older java versions. – user2504380 Oct 06 '14 at 09:28
  • Possibly duplicate: [Java 256-bit AES Password-Based Encryption](http://stackoverflow.com/questions/992019/java-256-bit-aes-password-based-encryption) – ursa Oct 06 '14 at 13:26
  • One major differnce is creating key from password and salt with which i am struggling right now – Shashank Oct 06 '14 at 13:28

0 Answers0