[font=Courier New,Courier,monospace]import java.io.UnsupportedEncodingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
DesEncrypter(SecretKey key) { try { eCipher = Cipher.getInstance("DES");
dCipher = Cipher.getInstance("DES");
eCipher.init(Cipher.ENCRYPT_MODE, key);
dCipher.init(Cipher.DECRYPT_MODE, key); } catch (javax.crypto.NoSuchPaddingException e)
{
} catch (java.security.NoSuchAlgorithmException e)
{
} catch (java.security.InvalidKeyException e)
{
} } public String encrypt(String str) { try { byte[] utf8 = str.getBytes("UTF8");
// Şifreleme byte[] enc = eCipher.doFinal(utf8);
// Bytes dizisini BASE64 ile karakter dizisine çevir return new sun.misc.BASE64Encoder().encode(enc); } catch (javax.crypto.BadPaddingException e)
{
} catch (IllegalBlockSizeException e)
{
} catch (UnsupportedEncodingException e)
{
} catch (java.io.IOException e)
{
} return null;
}
public String decrypt(String str)
{ try { byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
// Şifreyi çözme byte[] utf8 = dCipher.doFinal(dec);
return new String(utf8, "UTF8");
} catch (javax.crypto.BadPaddingException e)
{
} catch (IllegalBlockSizeException e)
{
} catch (UnsupportedEncodingException e)
{
} catch (java.io.IOException e)
{
} return null; } public static **** main(String[] args) { try
{ // Geçici bir anahtar oluştur SecretKey key = KeyGenerator.getInstance("DES").generateKey();
// Şifreleyecek objeyi yarat DesEncrypter encrypter = new DesEncrypter(key);
// Şifrele String encrypted = encrypter.encrypt("E-Bergi Mart sayısı"); System.out.println(encrypted);
// Şifreyi çöz String decrypted = encrypter.decrypt(encrypted); System.out.println(decrypted); } catch (Exception e)
{
}
}
}[/font]