Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: 1 2 [3] 4 5 ... 7
61  Game Development / Newbie & Debugging Questions / AES IV Update on: 2009-03-19 06:10:59
I currently have this class for encrypting/decrypting AES. How do I update the IV? I already have an updateIV() function but it doesn't seem to update the REAL IVParameterSpec.

Thanks.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package aescipher;

import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/**
 *
 * @author Ido
 */

public class Encryption {
    public static enum Mode {
        ENCRYPT_MODE, DECRYPT_MODE;
    }
   
    public static final String CIPHER = "AES/CBC/PKCS5Padding";
   
    protected Cipher cipher;
    protected Mode mode;
    protected byte[] iv;
    protected IvParameterSpec ivSpec;
    protected byte[] key;
   
    /**
     * Creates this Encryptor.
     * @param cipherMode Mode to use
     * @param key 128 bit AES key to use
     * @param iv 128 bit [16 byte] AES iv to use
     */

    public Encryption(Mode cipherMode, byte[] key, byte[] iv) {
        try {
            this.key = key;
            cipher = Cipher.getInstance(CIPHER);
            ivSpec = new IvParameterSpec(iv);
            SecretKeySpec aesKey = new SecretKeySpec(key, "AES");
            this.mode = cipherMode;
            if (cipherMode == Mode.ENCRYPT_MODE) {
                cipher.init(Cipher.ENCRYPT_MODE, aesKey, ivSpec);
            } else {
                cipher.init(Cipher.DECRYPT_MODE, aesKey, ivSpec);
            }
        } catch (InvalidKeyException ex) {
          Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidAlgorithmParameterException ex) {
          Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchPaddingException ex) {
            Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.iv = iv;
    }
   
    public byte[] crypt(byte[] in) {
        try {
          updateIV();
          System.out.print("New IV: ");
          printBytes(this.cipher.getIV());
          return cipher.doFinal(in);
        } catch (IllegalBlockSizeException ex) {
          Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        } catch (BadPaddingException ex) {
          Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
   
    public void printBytes(byte[] b) {
        System.out.print("(");
        for (int i = 0; i < b.length; i++) {
            System.out.print("0x" + Integer.toHexString(b[i]));
            if (i < b.length - 1) {
                System.out.print(", ");
            }
        }
        System.out.println(")");
    }
   
    public void updateIV() {
        for (int i = 0; i < this.iv.length; i++) {
            if (i < iv.length/2) { //16/2
                iv[i] ^= iv[i + 1];
                if (iv[i] > 127) {
                    iv[i] = 0x0A;
                }
                iv[i] ^= iv[i + 3];
                if (iv[i] > 127) {
                    iv[i] = 0x0D;
                }
            } else { //16/2
                iv[i] ^= iv[i - 3];
                if (iv[i] > 127) {
                    iv[i] = 0x0C;
                }
                iv[i] ^= iv[i - 2];
                if (iv[i] > 127) {
                    iv[i] = 0x1D;
                }                
            }
        }
        //cipher.update(iv, 0, iv.length);
    }
}
62  Game Development / Newbie & Debugging Questions / Re: [HELP] Library help on: 2009-02-17 06:41:31
the program doesn't even launch, so using try/catch is out of the question.  Roll Eyes
63  Game Development / Newbie & Debugging Questions / Re: [HELP] Library help on: 2009-02-12 07:13:09
Thats not the point. The point is to try and.. hmm.. see if the libraries exist. So far I can't get it to work because it gives a main class not found error when I don't have the libraries.
64  Game Development / Newbie & Debugging Questions / [HELP] Library help on: 2009-02-12 06:26:46
Ok, In my game at the moment, if you don't have the libraries under /lib it will give a main class not found error. How do I fix this, so like if they don't have the libraries it will try to download it for them? Or at least exit if it doesn't find the libraries? Right now the JVM isn't even launched if the libraries are not found so I have no clue.
65  Game Development / Newbie & Debugging Questions / Re: online Highscore on: 2009-02-05 08:11:27
you should have an encrypted packet that sends to the server then the server will validate it and add it to the table or else it doesn't. Never put the mysql pass/user in the client because then they can access your SQL server, and you'll have to also portforward 3306.

Best way IMO is to send a score gain packet everytime they gain a score then send an end of game packet to add it to the highscore.
66  Games Center / 4K Game Competition - 2009 / Re: Putty Shuffle on: 2009-02-03 12:35:49
[move]Wow nice game Cheesy[/move]
67  Game Development / Newbie & Debugging Questions / Re: global variable on: 2009-02-03 12:33:24
umm

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
        enemies = new Enemy[]{
             new Enemy("Ogre"),
             new Enemy("Ogre"),
             new Enemy("Ogre"),
             new Enemy("Ogre"),
             new Enemy("Gimp"),
             new Enemy("Gimp"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Overlord")
        };


should be

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
        Enemy[] enemies = {
             new Enemy("Ogre"),
             new Enemy("Ogre"),
             new Enemy("Ogre"),
             new Enemy("Ogre"),
             new Enemy("Gimp"),
             new Enemy("Gimp"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Rat"),
             new Enemy("Overlord")
        };
68  Game Development / Networking & Multiplayer / Re: Player movement. on: 2009-02-03 11:31:22
hmm, is it possible to send a list of the last movements in the last seconds, then write it to the other client and then the client can somehow interpolate/calculate the x/y of the other character? If that's possible, then I'd send a packet every second that has 10 frames in it..
69  Game Development / Newbie & Debugging Questions / Re: Why does my game pause? on: 2009-01-29 07:24:44
woot I fixed it I just had to make it undecorated and make a fake frame for it Tongue
70  Game Development / Newbie & Debugging Questions / Re: Why does my game pause? on: 2009-01-26 07:35:35
while (true) {
 //do game
}

it's a separate thread
71  Game Development / Newbie & Debugging Questions / Re: Why does my game pause? on: 2009-01-26 04:40:00
if (isFocusOwner())
draw();

 Roll Eyes



That DOES work, but when you click off the game it freezes even if the game window is still visible.
72  Game Development / Newbie & Debugging Questions / Re: Why does my game pause? on: 2009-01-26 00:23:41
But still, it it is minimized, it shouldn't paint, but it should still do the rest of the collision/ai stuff.  Undecided
73  Game Development / Newbie & Debugging Questions / Re: Why does my game pause? on: 2009-01-25 14:09:11
yes, it is really annoying. how do i fix it :\
74  Game Development / Newbie & Debugging Questions / Re: Why does my game pause? on: 2009-01-25 06:24:12
if it's minimized, will the code still run? just not paint?
75  Game Development / Newbie & Debugging Questions / Re: Why does my game pause? on: 2009-01-25 05:32:42
Well I used NetBeans and created a window with the GUI builder Desktop thing. It just freezes when you minimize it, and when you put it back in focus, it spams paint(..) for how many times paint(..) was missed while it was minimized.
76  Game Development / Newbie & Debugging Questions / Why does my game pause? on: 2009-01-25 03:11:04
Why does my game pause when I press the [ - ] button? It gets really annoying because my game is a MMO, and when you put the window back in focus, it repeats paint(...) like a million times..

Thanks.
77  Game Development / Newbie & Debugging Questions / Anyone know how to use GCJ? on: 2009-01-24 09:32:24
I'm trying to use GCJ, I've installed it, read all the docs, and its really difficult to use, does anyone know how to use it?
78  Game Development / Newbie & Debugging Questions / Re: Do you know I'm Black? on: 2009-01-23 12:14:12
you're black? thats nice..
79  Game Development / Newbie & Debugging Questions / Re: How to get a random number between 10 and 20 on: 2009-01-23 06:02:50
public int rand(int s, int e) {
 return (s + (int) (Math.random() * (e-s)));
}
80  Games Center / 4K Game Competition - 2009 / Re: MEG4kMAN, Mega Man in 4kb on: 2009-01-22 02:27:23

Exception in thread "Thread-7" java.lang.StringIndexOutOfBoundsException: String index out of range: -300
   at java.lang.String.charAt(Unknown Source)
   at S.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
81  Game Development / Newbie & Debugging Questions / Re: Disabling alt when on a JFrame? on: 2009-01-21 03:32:31
will a robot work? Or is the key never registered by a keyListener?
82  Game Development / Newbie & Debugging Questions / Re: Disabling alt when on a JFrame? on: 2009-01-20 22:56:54


Yeah, just played JetP4k on vista with java webstart. Just got this annoying menu to popup. Also, pressing right or left then alt causes you to keep moving right/left without stop even if you're not pressing any keys.

Anyway, would using a robot to press Alt again work?
83  Game Development / Newbie & Debugging Questions / Direct input? on: 2009-01-20 06:58:43
Is it possible to check the hardware directly for input (keys/mouse)? I need this because if you press a key in a jframe then click outside the JFrame, it won't register a keyReleased event.

Thanks.
84  Game Development / Newbie & Debugging Questions / Re: Disabling alt when on a JFrame? on: 2009-01-20 06:26:50
Just did an experiment. using even this code:

1  
2  
3  
4  
5  
   public static void main(String[] a) {
      JFrame w = new JFrame("this sux");
      w.setSize(300, 300);
      w.setVisible(true);
   }


creates that menu.
85  Game Development / Newbie & Debugging Questions / Re: Disabling alt when on a JFrame? on: 2009-01-20 06:16:08
My code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
    public void init() {
        try {
            processor = new PacketHandler();
        } catch (Exception e) {
            Console.w = false;
            e.printStackTrace();
            ErrorDialog ed = new ErrorDialog(Console.getWindow(), "Server unavailable", "Connecting to the server failed.");
            ed.setLocation(getScreenCenter(ed));
            ed.setTitle("Server Unavailable");
            ed.getCloseButton().addActionListener(new ActionListener() {
                @Override public void actionPerformed(ActionEvent ae) {
                    System.exit(0);
                }
            });
            ed.setVisible(true);
            Console.getWindow().dispose();
            Console.getApplication().setWindow(null);
            return;
        }
        initComponents();
        setMinimumSize(new Dimension(800, 600));
        setMaximumSize(new Dimension(800, 600));
        setResizable(false);
        ImageTransparencyTransformer t = ImageTransparencyTransformer.getInstance();
        setIconImage(
                t.filter(getToolkit().createImage(getClass().getResource("resources/images/icon.png")))
                );
        setLocation(getToolkit().getScreenSize().width / 2 - getSize().width / 2, getToolkit().getScreenSize().height / 2 - getSize().height / 2);
        addWindowListener(new WindowAdapter() {
            @Override public void windowClosing(WindowEvent we) {
                close();
            }
        });
        setTitle("Renoria");
        try {
            macro = new Robot();
        } catch (Exception e) {
            e.printStackTrace();
            ScreenManager s = ScreenManager.getInstance();
            s.restoreScreen();
            ErrorDialog d = new ErrorDialog(this, "GUI Error", "Creating the User Interface failed.");
            d.setVisible(true);
            this.setVisible(false);
        }
        macro.mouseMove(getToolkit().getScreenSize().width / 2,
                      getToolkit().getScreenSize().height / 2);
        Cursor c = getToolkit().createCustomCursor(getToolkit().createImage(""),
                                                   new Point(0,0), "");
        setCursor(c);
        setAlwaysOnTop(true);
        cursor = getToolkit().createImage(getClass().getResource("resources/images/cursor.png"));
        cursor = t.filter(cursor);
        defaultCursor = cursor;
        final AbstractMedia am = this.media;
        final MainWindow wi = this;
        addKeyListener(new KeyListener() {
            @Override public void keyPressed(KeyEvent key) {
                if (key.getKeyCode() == KeyEvent.VK_F12) {
                    takeScreenShot("Renoria-");
                    return;
                }
                if (key.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (key.isAltDown()) {
                        key.consume();
                        ScreenManager s = ScreenManager.getInstance();
                        if (s.getFullScreenWindow() != null) {
                            s.restoreScreen();
                        } else {
                            s.setFullScreen(dis);
                        }
                        return;
                    }
                }
                if (media != null)
                    media.keyPressed(key);
            }

            public void keyTyped(KeyEvent key) {
                if (media != null)
                    media.keyTyped(key);
            }

            public void keyReleased(KeyEvent key) {
                if (media != null)
                    media.keyReleased(key);
                if (key.getKeyCode() == KeyEvent.VK_ESCAPE && Console.testing) {
                    //System.exit(0);
                }
            }
        });
        setFocusTraversalKeysEnabled(false);
    }
86  Game Development / Newbie & Debugging Questions / Re: Disabling alt when on a JFrame? on: 2009-01-20 02:28:54
I don't have a JMenu. Its the default menu:



I've also tried setFocusTraversalKeysEnabled(false)
87  Game Development / Newbie & Debugging Questions / Re: Disabling alt when on a JFrame? on: 2009-01-19 09:18:34
Ooops lol, I meant alt. You know when you press it, it shows a menu on a JFrame? I need that to be disabled so I can use alt for jump.
88  Game Development / Newbie & Debugging Questions / Disabling alt when on a JFrame? on: 2009-01-18 11:44:22
When I press ALT on a JFrame, and I press the down or up arrow key, a menu appears. How do I disable this so I can actually use ALT in game?

Thanks.

89  Game Development / Newbie & Debugging Questions / Re: Creating a Data Patch? on: 2009-01-14 23:59:28
I'm talking about making EXE/Jar patches that patch/update data files, like Zip, or encrypted archive files, without redownloading the whole thing.
90  Game Development / Newbie & Debugging Questions / Re: Best Image for the job on: 2009-01-14 05:03:54
I use Image. I wrap it up in my own custom class so I can get the anchor/origin of the image.
Pages: 1 2 [3] 4 5 ... 7
 
Riven (848 views)
2019-09-04 15:33:17

hadezbladez (5799 views)
2018-11-16 13:46:03

hadezbladez (2605 views)
2018-11-16 13:41:33

hadezbladez (6215 views)
2018-11-16 13:35:35

hadezbladez (1501 views)
2018-11-16 13:32:03

EgonOlsen (4736 views)
2018-06-10 19:43:48

EgonOlsen (5794 views)
2018-06-10 19:43:44

EgonOlsen (3278 views)
2018-06-10 19:43:20

DesertCoockie (4176 views)
2018-05-13 18:23:11

nelsongames (5503 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!