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
private final String messageA; private final String messageB; private final Type type; private final long timeGenerated; private boolean processed;
messageB are the strings which are encrypted using
"AES/CTR/NoPadding" and encoded with
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
messageB and same procedure in reverse order when I want to get it back.
The encryption and decryption code is:
//Encryption Cipher cipherFinal = Cipher.getInstance("AES/CTR/NOPADDING"); cipherFinal.init(Cipher.ENCRYPT_MODE,TGS_KEY, Operation.generateIV(cipherFinal), Operation.random); String finalString = new String(Base64.encode (cipherFinal.doFinal (Operation.getByteArrayFromObject(ticket)))); //Decryption Cipher cipherFinal = Cipher.getInstance("AES/CTR/NOPADDING"); cipherFinal.init(Cipher.DECRYPT_MODE, TGS_KEY, Operation.generateIV(cipherFinal), Operation.random); byte decryptedText = cipherFinal.doFinal(messageA.getBytes()); Ticket ticket = (Ticket)Operation.getObjectFromByteArray(decryptedText);
I am getting different byte than the original one.
BYTE ARR TO BE ENCRYPTED : rO0ABXNyABJjb20ubXkuZGF0YS5... BYTE ARRAY RECOVERED : 7fK+CUqePrJAeTN8K7GLpXxhsyA...
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.