Click here to Skip to main content
16,005,169 members
Home / Discussions / Java
   

Java

 
GeneralRe: making a Search Engine Pin
Richard MacCutchan18-Nov-09 2:01
mveRichard MacCutchan18-Nov-09 2:01 
GeneralRe: making a Search Engine Pin
Nagy Vilmos18-Nov-09 2:35
professionalNagy Vilmos18-Nov-09 2:35 
JokeRe: making a Search Engine Pin
Richard MacCutchan18-Nov-09 2:54
mveRichard MacCutchan18-Nov-09 2:54 
QuestionJava program help!!! Pin
James WG Murphy17-Nov-09 15:57
James WG Murphy17-Nov-09 15:57 
AnswerRe: Java program help!!! Pin
tux_linux225-Nov-09 3:51
tux_linux225-Nov-09 3:51 
QuestionWindows Calc Pin
sparlay_pk17-Nov-09 5:06
sparlay_pk17-Nov-09 5:06 
AnswerRe: Windows Calc Pin
Nagy Vilmos17-Nov-09 5:29
professionalNagy Vilmos17-Nov-09 5:29 
Questiondecryption with AES Pin
mesho15-Nov-09 8:51
mesho15-Nov-09 8:51 
hi everybody Smile | :)

i'm trying to write a program that uses "brute force" to decrypt an encrypted message (using AES), where I only have the first 96-bits of the 128-bit secret key
when i complie i got this exception:

Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly paddedConfused | :confused:

my code:
public static byte[] encrypt (byte[] plainText , SecretKeySpec spc)<br />
	    throws NoSuchAlgorithmException,GeneralSecurityException  {<br />
	        Cipher cipher = Cipher.getInstance("AES");<br />
	        cipher.init(Cipher.ENCRYPT_MODE,spc);<br />
	        byte[] cipherText = cipher.doFinal( plainText);<br />
	        return cipherText ;<br />
	    }<br />
<br />
	    public static byte[] decrypt (byte[] cipherText , SecretKeySpec spec)<br />
	    throws NoSuchAlgorithmException,GeneralSecurityException {<br />
	        Cipher cipher = Cipher.getInstance("AES");<br />
	        cipher.init(Cipher.DECRYPT_MODE, spec);<br />
	        byte[] plainText = cipher.doFinal(cipherText);<br />
	        return plainText ;<br />
	    }<br />
<br />
	    public static void readfile(RandomAccessFile file, byte[] bytes) throws Exception<br />
	    {<br />
				file.seek(0);<br />
	            int offset = 0;<br />
	            int numRead = 0;<br />
	            while (offset < bytes.length<br />
	                   && (numRead=file.read(bytes, offset, bytes.length-offset)) >= 0) {<br />
	            offset += numRead;<br />
	            }<br />
	    }<br />
<br />
	    public static void main(String[] args) throws Exception {<br />
	try<br />
			{<br />
				// 1: open cipher file<br />
				RandomAccessFile cipherfile = new RandomAccessFile( "ciphertext2.dat", "r" );<br />
<br />
	            // read cipher text<br />
				byte[] bytes = new byte[(int)cipherfile.length()];<br />
	            readfile(cipherfile,bytes);<br />
<br />
	            // 3:<br />
	            RandomAccessFile file = new RandomAccessFile( "partial-key.dat", "r" );<br />
	            byte[] keybytes = new byte[(int)file.length()+4];<br />
	            readfile(file,keybytes);<br />
	            for(int i=0;i<256;i++)<br />
	            {<br />
	                keybytes[12]=(byte)i;<br />
	                for(int j=0;j<256;j++)<br />
	                {<br />
	                    keybytes[13]=(byte)j;<br />
	                    for(int k=0;k<265;k++)<br />
	                    {<br />
	                        keybytes[14]=(byte)k;<br />
	                        for(int l=0;l<265;l++)<br />
	                        {<br />
	                            keybytes[15]=(byte)l;<br />
	                            SecretKeySpec key = new SecretKeySpec(keybytes, "AES");<br />
	                            byte[] plain=new byte[(int)cipherfile.length()];<br />
	                            plain=decrypt (bytes,key);<br />
	                            for (int y=0;y<=plain.length;y++)<br />
	                                System.out.print((char)plain[y]);<br />
	                        }<br />
	                }<br />
	                }<br />
	            }<br />
<br />
	            file.close();<br />
<br />
	            // 5: close file<br />
				cipherfile.close();<br />
	        }<br />
			catch ( FileNotFoundException e)<br />
			{<br />
				System.out.println(e);<br />
			}<br />
			catch ( IOException e)<br />
			{<br />
				System.out.println(e);<br />
			}<br />
		}<br />


thanks in advanceRose | [Rose]
AnswerRe: decryption with AES Pin
Richard MacCutchan15-Nov-09 21:56
mveRichard MacCutchan15-Nov-09 21:56 
GeneralRe: decryption with AES Pin
mesho16-Nov-09 1:18
mesho16-Nov-09 1:18 
GeneralRe: decryption with AES Pin
Richard MacCutchan16-Nov-09 1:44
mveRichard MacCutchan16-Nov-09 1:44 
GeneralRe: decryption with AES Pin
mesho16-Nov-09 2:21
mesho16-Nov-09 2:21 
GeneralRe: decryption with AES Pin
Richard MacCutchan16-Nov-09 2:56
mveRichard MacCutchan16-Nov-09 2:56 
QuestionLoading different implementations of a class Pin
Klazen14-Nov-09 15:38
Klazen14-Nov-09 15:38 
AnswerRe: Loading different implementations of a class Pin
Nagy Vilmos15-Nov-09 22:29
professionalNagy Vilmos15-Nov-09 22:29 
GeneralRe: Loading different implementations of a class Pin
Klazen16-Nov-09 7:30
Klazen16-Nov-09 7:30 
Questionsharing a directory/folder in Java Pin
VontinaAlexa13-Nov-09 5:52
VontinaAlexa13-Nov-09 5:52 
AnswerRe: sharing a directory/folder in Java Pin
David Skelly13-Nov-09 6:23
David Skelly13-Nov-09 6:23 
GeneralRe: sharing a directory/folder in Java Pin
VontinaAlexa13-Nov-09 6:33
VontinaAlexa13-Nov-09 6:33 
Questionjava servlet - error HTTP 500 - java.lang.nullpointer exception Pin
golisarmi11-Nov-09 1:01
golisarmi11-Nov-09 1:01 
AnswerRe: java servlet - error HTTP 500 - java.lang.nullpointer exception Pin
David Skelly11-Nov-09 2:32
David Skelly11-Nov-09 2:32 
GeneralRe: java servlet - error HTTP 500 - java.lang.nullpointer exception [modified] Pin
golisarmi11-Nov-09 2:43
golisarmi11-Nov-09 2:43 
GeneralRe: java servlet - error HTTP 500 - java.lang.nullpointer exception Pin
sparlay_pk16-Nov-09 7:49
sparlay_pk16-Nov-09 7:49 
QuestionSaving Forms to an XML file or .txt file Pin
Clement Tientcheu10-Nov-09 18:20
Clement Tientcheu10-Nov-09 18:20 
AnswerRe: Saving Forms to an XML file or .txt file Pin
sparlay_pk16-Nov-09 7:56
sparlay_pk16-Nov-09 7:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.