Evening. I am totally new to security. after hours of reading about keys and de-enCryption I created this experiment class, that most is copy&paste from sun. All I need is a class that in a simple way decrypt an password file.
Am I even close to the best solution? Code below has two errors, both says "cant find symbol" when mouse over in NetBeans.
public class EnDeCrypt {
static byte[] encodedAlgParams;
public static KeyPair myKey()throws Exception{
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("PBE");
keyPairGenerator.initialize(1024);
KeyPair keyPair = keyPairGenerator.genKeyPair();
return keyPair;
}
public static void enCrypt() throws Exception{
try {
Cipher c = Cipher.getInstance("PBEWithMD5AndDES");
c.init(Cipher.ENCRYPT_MODE, myKey()); // *1* <---mouse over c.init says "cant find symbol"
byte[] cipherText = c.doFinal(text.getBytes());
AlgorithmParameters algParams = c.getParameters();
encodedAlgParams = algParams.getEncoded();
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(EnDeCrypt.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchPaddingException ex) {
Logger.getLogger(EnDeCrypt.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void deCrypt(String text) throws Exception {
AlgorithmParameters algParams;
algParams = AlgorithmParameters.getInstance("PBEWithMD5AndDES");
algParams.init(encodedAlgParams);
Cipher c = Cipher.getInstance("PBEWithMD5AndDES");
c.init(Cipher.DECRYPT_MODE, myKey, algParams);// *2*<-- mouse over myKey() says, "cant find this symbol"
}
}
{code}