1

In my backend side they have created the encrypted message using AES algorithm with 16 byte key with this piece of code

Key: h7Ui63Mzqj61G87j

    public static String encrypt(String data, byte[] secretKey) throws Exception {
    Key key = generateKey(secretKey);
    Cipher c = Cipher.getInstance(ALGORITHM);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encVal = c.doFinal(data.getBytes());
    String encryptedValue = new BASE64Encoder().encode(encVal);
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("DataToEncrypt: %s, encryptedValue: %s", data, encryptedValue));
    }
    return encryptedValue;
}

But I am unable to decrypt the message with the same key using AES algorithm.

5
  • Your key is 16 characters long. How do you convert it into 32 bytes? Commented Jan 31, 2017 at 7:55
  • Ok, now we have 16 characters vs 16 bytes. How do you convert from characters to bytes? Commented Jan 31, 2017 at 8:57
  • 1
    And please show the Objective-C code you have so far. And tell us what "i cant able to decrypt message" means. Doesn't it compile? Does it crash? Does it produce the wrong output? What the input, what's the expected output and what's the effective output? Commented Jan 31, 2017 at 8:59
  • From the server side they encrypt the message with the key and in objective-c code can't decrypt the message with the same key Commented Jan 31, 2017 at 9:17
  • am getting null value. Commented Jan 31, 2017 at 9:17

1 Answer 1

1

Please refer this below link,

https://github.com/callmewhy/why-encrypt

Hope its help full.

Sign up to request clarification or add additional context in comments.

2 Comments

Post the relevant info in case the link ever rots.
The referenced code uses ECB mode. Do not use ECB mode, it is not secure, see ECB mode, scroll down to the Penguin. Instead use CBC mode with a random IV, just prefix the encrypted data with the IV for use in decryption, it does not need to not secret.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.