DESで質問です。下記のクラスを作り、mainから呼び出すとエラーになります。
問題が見つけられません。ご教授いただけないでしょうか。
public class CompressUtils {
private static final Cipher encrypt;
private static final Cipher decrypt;
private static final SecretKey sk;
static {
String kagi = "abc12345";
DESKeySpec dk = new DESKeySpec(kagi.getBytes());
SecretKeyFactory kf = SecretKeyFactory.getInstance("DES");
sk = kf.generateSecret(dk);
encrypt = Cipher.getInstance("DES");
encrypt.init(Cipher.ENCRYPT_MODE, sk);
decrypt = Cipher.getInstance("DES");
decrypt.init(Cipher.DECRYPT_MODE, sk);
}
public static String decrypt(String string) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException {
byte[] base = string.getBytes();
byte[] dec = decrypt.doFinal(base);
return new String(dec);
}
public static String encrypt(String string) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException {
byte[] base = string.getBytes();
byte[] enc = encrypt.doFinal(base);
return new String(enc);
}
}
String ret = CompressUtils.encrypt( "hogehoge" );
System.out.println( CompressUtils.decrypt( ret ) );