如何在我的gwt应用程序中导入java.security.*

如何在我的gwt应用程序中导入java.security.*,java,gwt,jar,rsa,browser-plugin,Java,Gwt,Jar,Rsa,Browser Plugin,我想用gwt开发一个插件。它必须使用java.security.*在客户端生成密钥。 我已经提出了所有的要求 但它显示出以下错误 加载模块 coreservlets.gwtap1 Loading inherited module 'coreservlets.GwtApp1' Loading inherited module 'java.security.KeyPair' [ERROR] Unable to find 'java/security/KeyPair.gwt.xm

我想用gwt开发一个插件。它必须使用java.security.*在客户端生成密钥。 我已经提出了所有的要求 但它显示出以下错误

加载模块

coreservlets.gwtap1

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'
我在gwtap1.gwt.xml文件中继承了所有相关类,如“java.security.KeyPair”

我还将jar包含在类路径中,但错误仍然没有消失。 我该怎么办?请建议 这是我的java代码

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;
}

}在
.gwt.xml
文件中
指的是另一个
.gwt.xml
文件。我怀疑你把它当作java
import…
来使用

如果您想在GWT中使用
java.security.KeyPair
clientside,您应该做的是确定GWT编译器可以使用源代码。这是使用
.gwt.xml
文件中的
条目完成的

您可能想访问该页面,遗憾的是您将看到,
javax.*
包都不受支持,所以祝您的项目好运。。。也许您应该只在服务器端使用
KeyPair
保存代码


希望对您有所帮助。

对于密钥生成,您可以使用该库,但要准备好处理某些性能问题和不支持的功能

[编辑]
不久前,我使用jsni成功地包装了一个纯js rsa解决方案。我拿的js是库

你的“KeyPair.gwt.xml”似乎有问题。检查所有内容是否正确或粘贴到此处。感谢您的帮助,事实上我是gwt新手。我见过各种开发gwt应用程序的示例,例如,但无法了解如何使用java.security.*jar。请您详细解释一下。再次感谢gwt编译器需要客户端中每个类的源代码。您可以从JDK中的
src.zip
中提取
密钥对(以及相关/引用的类!),并使其生效。感谢您的建议,但我不必使用gwt chrypto lib。您是否有任何其他可能的方法来解决此问题。不幸的是,gwt jre中没有模拟java.security,因此,尽管您创建了一个包含原始java文件的模块(来自sun/oracle),但您将无法使用这些类。我已经编辑了我的回复,以包含一个jsni可能的解决方案。这也可以是我的选择。总的来说,我要做的是开发浏览器插件,安装时将在客户端生成密钥,公钥将发送到服务器,服务器将加密文件,加密文件将由我在客户端的私钥解密我正在做的一个可能的方法是使用gwt生成密钥,因为上面的问题正在发生。所以我需要建议我应该做什么,还有他们生成公钥的任何其他方法,应该在服务器端算法上工作,由于使用js生成密钥不起作用。我是gwt新手。再次感谢您的回复。使用jsbn生成的密钥应该在使用openssl的服务器端工作,所以我猜您可以在服务器中使用javax.security,因为它与openssl兼容。在包装jsbn之前,您可以在他们的站点()中使用演示页面,生成密钥和消息,并尝试使用服务器java实现进行解密/加密。一旦您完成了这项工作,您就可以在客户端包装您需要的js方法needed@ManoloCarrascoMo尼诺,你能帮我回答这个相关的问题吗?