3

I have been trying to convert a Java class into DLL using IKVM. IKVM converts that easily without errors. But while running it in VS, it throws the following exceptions:

System.TypeInitializationException: 'The type initializer for 'sun.security.jca.Providers' threw an exception.
**1 of 2 Inner Exceptions** : TypeInitializationException: The type initializer for 'java.security.Security' threw an exception.
**2 of 2 Inner Exceptions** : -     InnerException  {"Method not found: 'Void System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.Security.AccessControl.FileSystemRights, System.IO.FileShare, Int32, System.IO.FileOptions)'."}  System.Exception {System.MissingMethodException}.

I can't understand the reason of these Exceptions.

My Java Code is :

package aesgzip;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.Scanner;

public class AESGzip {

    private static final String key = MyKeyString;
    private static final String IV = MyIV;

    public static byte[] decrypt(byte[] encrypted) {
        try {
            IvParameterSpec IVSpec = new IvParameterSpec(IV.getBytes("UTF-8"));
            SecretKeySpec KEYSpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            cipher.init(2, KEYSpec, IVSpec);


            return cipher.doFinal(encrypted);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }
}

My C# Code is :

using System;
using aesgzip;

namespace AESTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            byte[] b = Convert.FromBase64String(myBASE64String);
            byte[] x = AESGzip.decrypt(b);
           Console.WriteLine(x);
        }

    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
PaxDoc
  • 31
  • 3

0 Answers0