title: Encryption/Decryption in C# and Java
body: <p>i want to decrypt my encrpyted String in Java on Android. </p>
  
  <p>With the following code i encrypted my raw String in C#:</p>
  
  <pre><code>        public static string Encrypt(string decryptedString)
      {
          DESCryptoServiceProvider desProvider = new DESCryptoServiceProvider();
          desProvider.Mode = CipherMode.ECB;
          desProvider.Padding = PaddingMode.PKCS7;
          desProvider.Key = Encoding.ASCII.GetBytes("password");
          using (MemoryStream stream = new MemoryStream())
          {
              using (CryptoStream cs = new CryptoStream(stream, desProvider.CreateEncryptor(), CryptoStreamMode.Write))
              {
                  byte[] data = Encoding.Default.GetBytes(decryptedString);
                  cs.Write(data, 0, data.Length);
                  cs.FlushFinalBlock();
                  return Convert.ToBase64String(stream.ToArray());
              }
          }
      }
  </code></pre>
  
  <p>I tried to decrypt it in Java:</p>
  
  <pre><code>   public String decrypt(){
         String keyStr = "password";
         String msg = "KGFL1GG5VLQ=";
         String erg = "";
         try{
  
  
         KeySpec ks = new DESKeySpec(keyStr.getBytes("UTF-8"));
         SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(ks);
         IvParameterSpec iv = new IvParameterSpec(Hex.decodeHex("1234567890ABCDEF".toCharArray()));
         Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
         cipher.init(Cipher.DECRYPT_MODE, key, iv);
  
         byte[] decoded = cipher.doFinal(Base64.decodeBase64(msg));
         erg = new String(decoded);
         } catch (Exception e){
             erg = "error";
         }
         return erg;
  
     }
  </code></pre>
  
  <p>I use the commons-codec-1.8.jar. It crashes with the following Error:</p>
  
  <pre><code>W/dalvikvm(17859): VFY: unable to resolve static method 339: Lorg/apache/commons/codec/binary/Base64;.decodeBase64 (Ljava/lang/String;)[B
  </code></pre>
  
  <p>Please point out where I'm going wrong.</p>