Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  decod.class
Language: JAVA
Code:
import java.io.FileInputStream;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import org.apache.commons.codec.binary.Base64;


 
public class decod {
        
    public byte[] getMD5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            return md.digest(input.getBytes());            
        }
          catch (Exception e) {
            e.printStackTrace();
        }
        return null;     
    }
    
    public byte[] deARCFOUR(byte[] key, byte[] cipherText) {
         try {              
                
           Cipher rc4Decrypt = Cipher.getInstance("RC4");
           SecretKeySpec rc4Key = new SecretKeySpec(key, "RC4");
           rc4Decrypt.init(Cipher.DECRYPT_MODE, rc4Key);
           byte [] clearText = rc4Decrypt.update(cipherText);
     
           
           
           return clearText;
         }
        catch (Exception e) {
            e.printStackTrace();
        }     
         return null;         
    }
    
    
    public String demo(String key, String Base64CipheredText) {
         
         System.out.println ("Base64CipheredText:");
         System.out.println (Base64CipheredText);         
         
         
         byte[] cipherText = Base64.decodeBase64(Base64CipheredText);
         System.out.println ("CipheredText:");
         System.out.println (DatatypeConverter.printHexBinary(cipherText));
         
                           
         System.out.println ("Key:");
         System.out.println (key);
                  
         byte[] kh=getMD5(key);         
         System.out.println ("MD5 key hash:");
         System.out.println (DatatypeConverter.printHexBinary(kh));
         
                
         
         
         
         String clearText=new String(deARCFOUR(kh,cipherText));
         System.out.println ("ClearText");
         System.out.println (clearText);
         
         return clearText;
         
         
    }
    
    
    
    
    
 
    public static void main(String[] args)  {
         
         
         decod f=new decod();
         f.demo (args[0],args[1]);
         
    }
}
Comments: