Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

I am new to cryptography so forgive me if I am doing anything stupid. I am following the Cryptography in JAVA book. I am creating my own kerberos. I am stuck at a point.

I have Message class which will take care of every interaction between client, KDC, FS, and AS.

    private final String messageA;
    private final String messageB;
    private final Type type;
    private final long timeGenerated;
    private boolean processed;

messageA and messageB are the strings which are encrypted using "AES/CTR/NoPadding" and encoded with base64(bouncy castle)

I have a ticket class which is a ticket representation of TGT.

private String userID;
private String ip;
private String ticketID;
private Long validity;
private final Type type;
private final long timeGenerated;
private Key key;

Now, here is the problem,

I am serializing the ticket object, encrypting it, encoding it using base64 and setting that string to messageA or messageB and same procedure in reverse order when I want to get it back.

The encryption and decryption code is:

    Cipher cipherFinal = Cipher.getInstance("AES/CTR/NOPADDING");
String finalString = new String(Base64.encode

Cipher cipherFinal = Cipher.getInstance("AES/CTR/NOPADDING");
cipherFinal.init(Cipher.DECRYPT_MODE, TGS_KEY, 
byte[] decryptedText = cipherFinal.doFinal(messageA.getBytes());

Ticket ticket = (Ticket)Operation.getObjectFromByteArray(decryptedText);

I am getting different byte[] than the original one.


The problem is with the serialization, the serialized byte[] is really big in size for a single object like 532 in length.

My question is, is there any fixed length of blocks it decrypts or maximum allowed length or i am doing anything wrong in encryption or decryption?

Should I make any changes with the code?

Please help. Thanks in advance.

share|improve this question
The IV you use for encryption needs to be transmitted to the box doing decryption and used in decryption. In your code you are instead generating a new IV at at each end. This is why the decryption doesn't give back the proper plaintext. –  mikeazo Feb 21 at 13:21
Thank you so much... You saved me. It's working fine now. –  ADi Feb 22 at 0:00
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.