1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power

    New to crypto. decrypting code using the bouncycastle API would not work.


    I am new to crypto and am planning to use a Key and cipher text and to decrypt with this so i get a message. But this doesnt seem to work. Any ideas ??

    String Key = "140b41b22a29beb4061bda66b6747e14";
    String ct2 = "2e4b7465d5290d0c0e6c6822236e1daafb94ffe0c5da05d9476be028ad7c1d81";

    AESEngine aes = new AESEngine();
    byte[] keyBytes = new BigInteger(Key, 16).toByteArray();
    byte[] cT2Bytes = new BigInteger(ct2, 16).toByteArray();
    byte[] payload = new byte[192];

    CipherParameters key = (new KeyParameter(keyBytes)); // hex-byte key
    aes.init(false, key); // if false, it will decrypt instead of encrypt
    aes.processBlock(cT1Bytes, 0, payload, 0); // it processes block by block

    String res = new String(payload);

    System.out.println(res); // result : some weird letters...

    -Muhammad Salman
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Rep Power
    It looks like the data is CBC encrypted. I'm not familiar with Bouncycastle's API, but I don't see you setting a cipher mode anywhere in that code.

    The cleartext appears to be 24 bytes of binary + PKCS5 padding. It doesn't appear to be meaningful interpreted as text. Instead of trying to turn it into a string you should be interpreting the bytes according to whatever format you expect the message to be in.

    (Aside: in the future, please surround code with [code]...[/code] tags to make it easier to read.)
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo