Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to import java.security.* in my gwt application

i want to develop a plugin using gwt. It has to use java.security.* for the key generation on client side. i have made all requirement But it is showing following error.

Loading modules

coreservlets.GwtApp1

Loading inherited module 'coreservlets.GwtApp1'
    Loading inherited module 'java.security.KeyPair'
       [ERROR] Unable to find 'java/security/KeyPair.gwt.xml' on your classpath; >could be a typo, or maybe you forgot to include a classpath entry for source?
    [ERROR] Line 15: Unexpected exception while processing element 'inherits'

i have inherited all the related class like "java.security.KeyPair" in my gwtapp1.gwt.xml file

also i included jar in classpath itself.but still the error has not gone. what should i do.plz suggest here is my java code

package coreservlets.client;

import java.io.UnsupportedEncodingException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;


public class Keygen {

private PrivateKey privKey;
private PublicKey pubKey;
private static Keygen keygen = null;

private Keygen() {

}

public static Keygen getInstance() {

    if (keygen == null) {
        keygen = new Keygen();
    }

    return keygen;
}

public void KeyGenerator(String ALGORITHAM) {
    KeyPairGenerator keyGen = null;
    SecureRandom random = null;
    try {
        keyGen = KeyPairGenerator.getInstance(ALGORITHAM);
    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace();
    }
    try {
        random = SecureRandom.getInstance("SHA1PRNG", "SUN");
        //random = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();

    } catch (NoSuchProviderException ex) {
        ex.printStackTrace();
    }

    //keyGen.initialize(1024, random);
    keyGen.initialize(1024);
    KeyPair key = keyGen.generateKeyPair();
    privKey = key.getPrivate();
    pubKey = key.getPublic();

}

public String getPubKeyasString() {
    //return Base64.encodeBase64String(pubKey.getEncoded());
    try {
        return new String(pubKey.getEncoded(),"ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
public String getPriKeyasString() {
    //return Base64.encodeBase64String(privKey.getEncoded());
    try {
        return new String(privKey.getEncoded(),"ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

}

like image 549
powerPlug Avatar asked Jan 24 '26 20:01

powerPlug


1 Answers

For key generation you can use the gwt-crypto library, but be prepared to certain performance issues and unsupported features.

[Edit] Some time ago, I did success wrapping a pure js rsa solution using jsni. The js I took was the jsbn.js library

like image 55
Manolo Carrasco Moñino Avatar answered Jan 27 '26 09:01

Manolo Carrasco Moñino