MetoDe ViGeneRe
Tehnik kriptografi berikutnya yang dapat diperkenalkan kepada para pemula, anak-anak Pramuka Penggalang ataupun sebagai permainan saat boot champ adalah sistem sandi Vigenère.
Sistem sandi ini pertama kali dipopulerkan oleh Blaise de Vigenère seorang diplomat Perancis pada abad 15, sehingga disebutlah metode ini dengan sistem sandi Vigenère
Sistem sandi ini pertama kali dipopulerkan oleh Blaise de Vigenère seorang diplomat Perancis pada abad 15, sehingga disebutlah metode ini dengan sistem sandi Vigenère
Sistem sandi Vigenère adalah sistem sandi substitusi multi-alfabet, yaitu sistem sandi Caesar tetapi dengan pergeseran alfabet yang berlainan disesuaikan dengan kata kuncinya.
Yang dimaksud sistem sandi substitusi adalah menyandi dengan cara mengganti huruf-huruf pesan/teks aslinya dengan huruf-huruf sandi. Sistem sandi Caesar dan Viginère termasuk metode sistem sandi ini. Bahkan sistem sandi substitusi merupakan sistem sandi yang dipakai pula dalam kriptografi modern, dengan variasi-variasi yang terus berkembang.
contoh :
kata kunci : MERAPI
pesan asli : SUKSES ADALAH PERMAINAN PIKIRAN
alfabet biasa :
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
alfabet sistem sandi Vigenère dengan kata kunci MERAPI :
M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
E F G H I J K L M N O P Q R S T U V W X Y Z A B C D
R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
sehingga
S dengan pergeseran M = E; U dengan pergeseran E = Y; K dengan pergeseran R = B; S dengan pergeseran A = S; E dengan pergeseran P = T; S dengan pergeseran I = A; A dengan pergeseran M = M; D dengan pergeseran E = H; dsb….. sampai N dengan pergeseran A = N
pesan tersandi : EYBSTA MHRLPP BIIMPQZEE PXSUVRN
JaVa Crypto
/*
* Created on Apr 5, 2005
*/
package kripto;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.CertificateException;
import java.nio.charset.Charset;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
/**
* @author bangamri
*/
public class Asimetrik {
private static void pembangkitanPasanganKunci(String alias, String namaDepan, String namaBelakang, String unit, String organisasi, String negara, String passwordKunci, String keyStore) {
try{
String perintah=”E://jdk1.5.0/bin/keytool -genkey -alias “+alias+” -keyalg RSA -dname \”cn=”+namaDepan+” “+namaBelakang+”, ou=”+unit+”, o=”+organisasi+”, c=”+negara+”\” -keysize 1024 -keypass “+passwordKunci+” -keystore “+keyStore+” -storepass Ultimate10″;
System.out.println(perintah);
Process proses=Runtime.getRuntime().exec(perintah);
proses.waitFor();
KeyStore ks=KeyStore.getInstance(“JKS”);
FileInputStream is=new FileInputStream(“KeyStore.jks”);
ks.load(is,new String(“Ultimate10″).toCharArray());
Certificate cert=ks.getCertificate(alias);
byte[] buffer=cert.getEncoded();
FileOutputStream os=new FileOutputStream(alias+”.crt”);
Writer wr = new OutputStreamWriter(os, Charset.forName(“UTF-8″));
wr.write(“—–BEGIN CERTIFICATE—–\n”);
wr.write(new sun.misc.BASE64Encoder().encode(buffer));
wr.write(“\n—–END CERTIFICATE—–\n”);
wr.flush();
os.close();
}catch(IOException e){
}catch(InterruptedException e){
}catch(CertificateException e){
}catch(KeyStoreException e){
}catch(NoSuchAlgorithmException e){
}finally{
System.out.println(“Pembangkitan kunci berhasil.”);
}
}
private static void enkrip(String alias, String fileSertifikat, String filePlain, String fileCipher) {
try{
FileInputStream is=new FileInputStream(fileSertifikat);
CertificateFactory cf=CertificateFactory.getInstance(“X.509″);
Certificate cert=cf.generateCertificate(is);
PublicKey pub=cert.getPublicKey();
File pla=new File(filePlain);
File cip=new File(fileCipher);
Cipher enkripsi=Cipher.getInstance(“RSA”);
enkripsi.init(Cipher.ENCRYPT_MODE,pub);
InputStream isPla=new FileInputStream(pla);
OutputStream osCip=new FileOutputStream(cip);
osCip=new CipherOutputStream(osCip,enkripsi);
byte[] buffer=new byte[1024];
int n=0;
while((n=isPla.read(buffer))>=0) {
osCip.write(buffer,0,n);
}
osCip.close();
isPla.close();
}catch(Exception e){
System.out.println(e);
}finally{
System.out.println(“Enkripsi sukses”);
}
}
private static void dekrip(String alias, String fileKeystore, String fileCipher, String filePlain) {
try {
FileInputStream is=new FileInputStream(fileKeystore);
KeyStore ks=KeyStore.getInstance(“JKS”);
ks.load(is, new String(“Ultimate10″).toCharArray());
Key kunci=ks.getKey(alias,new String(“Ultimate10″).toCharArray());
PrivateKey priv=(PrivateKey)kunci;
File fileCip=new File(fileCipher);
File filePla=new File(filePlain);
Cipher dekripsi=Cipher.getInstance(“RSA”);
dekripsi.init(Cipher.DECRYPT_MODE,priv);
InputStream isCip=new FileInputStream(fileCip);
OutputStream osPla=new FileOutputStream(filePla);
isCip=new CipherInputStream(isCip,dekripsi);
byte[] buffer=new byte[1024];
int n=0;
while ((n=isCip.read(buffer))>=0) {
osPla.write(buffer,0,n);
}
isCip.close();
osPla.close();
}catch(Exception e) {
System.out.println(e);
}finally{
System.out.println(“Dekripsi sukses”);
}
}
public static void main(String[] args) {
//pembangkitanPasanganKunci(“alice”,”Alice”,”Silverstone”,”Espionage”,”CIA”,”US”,
“Ultimate10″,”KeyStore.jks”);
enkrip(“alice”,”alice.crt”,”pesan.txt”,”pesan.enc”);
dekrip(“alice”,”KeyStore.jks”,”pesan.enc”,”pesan2.txt”);
}
}
taken from : javatingkir.blogspot.com
Cryptographic Algorithms
There are of course a wide range of cryptographic algorithms in use. The following are amongst the most well known:
DES
This is the ‘Data Encryption Standard’. This is a cipher that operates on 64-bit blocks of data, using a 56-bit key. It is a ‘private key’ system. Further Details on the DES Algorithm
RSA
RSA is a public-key system designed by Rivest, Shamir, and Adleman. Further Details on the RSA Algorithm
HASH
A ‘hash algorithm’ is used for computing a condensed representation of a fixed length message/file. This is sometimes known as a ‘message digest’, or a ‘fingerprint’..
MD5
MD5 is a 128 bit message digest function. It was developed by Ron Rivest. Further Details on the MD5 Algorithm
AES
This is the Advanced Encryption Standard (using the Rijndael block cipher) approved by NIST.
SHA-1
SHA-1 is a hashing algorithm similar in structure to MD5, but producing a digest of 160 bits (20 bytes).Because of the large digest size, it is less likely that two different messages will have the same SHA-1 message digest. For this reason SHA-1 is recommended in preference to MD5.
HMAC
HMAC is a hashing method that uses a key in conjunction with an algorithm such as MD5 or SHA-1. Thus one can refer to HMAC-MD5 and HMAC-SHA1.
taken from : http://www.cryptographyworld.com/algo.htm
