
-----------------------------------
randint
Fri Feb 03, 2012 6:39 pm

How to: Base 64 Encrypting/Decrypting
-----------------------------------
This is a very simple (but insecure) way to encrypt and/or decrypt a String using Base64
1. Make sure you have the package "org.apache.commons.codec.binary.*" installed in your system, if not, download it from 
import org.apache.commons.codec.binary.*;
import java.io.*;
public class BASE64ENCODEDECODE
{
    public static void main (String args
Hopefully this works for you!

-----------------------------------
Tony
Fri Feb 03, 2012 6:57 pm

RE:How to: Base 64 Encrypting/Decrypting
-----------------------------------
as the class name suggests, Base64 is an encoding method (not encyrption). Suggesting otherwise is misleading.

Also, you're catching Throwable, which will attempt to catch more than just Exceptions.

-----------------------------------
TokenHerbz
Sat Mar 17, 2012 9:22 pm

RE:How to: Base 64 Encrypting/Decrypting
-----------------------------------
i thought to catch an exception you must have that at the class declaration...
EX:
[code]
public static void main (String args[]) throws IOException {
}
[/code]

please let me know if im mistaken and why / how it all really works (the exceptions).

EDIT:
I also just wanted to comment on the naming conventions used about, i Dislike how the class was named, I think something more suitable would be, "Base_64_EncodeDecode"
I guess i want to share my opinion with other ones to while I'm on this case....
[code]
String sStringVar = "string;
int iNumber = 76;
boolean bAnswerIsTrue = false;
double dTotalAmount;"
int[][] aGrid = new int[5][5];
Scanner scanUserInput = new Scanner;
[/code]

just for a few, do you guys think its necessary or not?..  if you can see how the variables are defined...

-----------------------------------
DemonWasp
Sat Mar 17, 2012 10:26 pm

RE:How to: Base 64 Encrypting/Decrypting
-----------------------------------
Token:

1. You only declare 'throws' for exceptions you actually throw. His main() method doesn't throw anything of any kind, so it doesn't list a 'throws' clause. You'll notice he has catch ( Throwable t ), which catches the root exception-type class, Throwable. Exception extends Throwable. This will catch ANYTHING that gets thrown, including things you're not generally supposed to catch, like OutOfMemoryError or StackOverflowError. Since no exception can ever "escape" main(), main() doesn't throw anything.

2. Java has standards and naming conventions. If you aren't following them, you are probably wrong. Class names should be NamedLikeThis and should be a noun. This class could reasonably be called "Base64EncoderMain" or "Base64EncoderRuntime" or similar. You are correct that all-caps is a poor decision, though.

3. Hungarian naming conventions ('sStringVar', 'iNumber', see: http://en.wikipedia.org/wiki/Hungarian_notation ) went out of style around when we invented IDEs. I haven't seen anyone use them in code written since about 1990, so please don't do so yourself. Variable names should be nouns and should correspond to how they will be used locally.
