gnu-crypto-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNU Crypto] Problem padding


From: sgaston (sent by Nabble.com)
Subject: [GNU Crypto] Problem padding
Date: Mon, 12 Dec 2005 05:51:10 -0800 (PST)

Hi, (sorry for my english, im from ARgentine :( )

i have a very hard problem...well i think its hard :(
i dont have a good understanding of cryptography or cipher...i
just wanna do a padding and unpadding text.
im trying to padding a text just like the padding example say...but when
i try to unpadding the text remains padding...anyone can help me please?
Here is my code and my console output.
Like you see, my input and output are padded... what am i doing wrong!!??
------------------
<code>
try {
        IPad padding = PadFactory.getInstance("PKCS7");
        Cipher cipher = getCipher();
        int blockSize = cipher.getBlockSize();
       
    padding.init(blockSize);
    byte[] input = "HOLA MMMMMMUNDO".getBytes();
   
    byte[] pad = padding.pad(input, 0, input.length);    
   
    byte[] pt = new byte[input.length + pad.length];
    byte[] ct = new byte[pt.length];
    byte[] cpt = new byte[pt.length];
    System.arraycopy(input, 0, pt, 0, input.length);
    System.arraycopy(pad, 0, pt, input.length, pad.length);
    int unpad = padding.unpad(cpt, 0, cpt.length);
    byte[] output = new byte[cpt.length - unpad];
    System.arraycopy(cpt, 0, output, 0, output.length);
           
    System.out.println("TEST " + input + " -- " + output);
</code>
<console output>
TEST address@hidden -- address@hidden
</console output>

Sent from the Gnu - Crypto - Discuss forum at Nabble.com:
Problem padding
reply via email to

[Prev in Thread] Current Thread [Next in Thread]