0

我正在使用以下代码生成加密密码:

class DuplicateHandler<T> implements AsyncCallback<User> {
  public void onFailure(Throwable ex) {
    Window.alert("RPC call failed.");
  }

  public void onSuccess(User result) {
    User u = result;
    if (u == null) {
      String pw_hash = BCrypt.hashpw(passwordTextBoxEmail.getText(),
          BCrypt.gensalt());
      System.out.println("Hashed password lenth is: " + pw_hash.length());
      AsyncCallback<User> callback = new CreationHandler<User>();
      rpc.createUser(textBoxAccount.getText(), pw_hash, null, null, null,
          callback);
    } else {
      Window
          .alert("Username already in use. Please select another Username.");
    }
  }
}

我收到以下错误:

[DEBUG] [org.AwardTracker.AwardTracker] - Validating units:
[INFO] [org.AwardTracker.AwardTracker] - Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO] [org.AwardTracker.AwardTracker] - Module org.AwardTracker.AwardTracker has been loaded
[ERROR] [org.AwardTracker.AwardTracker] - Errors in 'file:/C:/Users/Glyndwr/Eclipse/Workspace/AwardTracker/src/org/AwardTracker/client/BCrypt.java'
[ERROR] [org.AwardTracker.AwardTracker] - Line 535: Cannot invoke clone() on the array type int[]
[ERROR] [org.AwardTracker.AwardTracker] - Line 536: Cannot invoke clone() on the array type int[]
[ERROR] [org.AwardTracker.AwardTracker] - Line 609: Cannot invoke clone() on the array type int[]
[ERROR] [org.AwardTracker.AwardTracker] - Line 706: No source code is available for type java.security.SecureRandom; did you forget to inherit a required module?
[ERROR] [org.AwardTracker.AwardTracker] - Uncaught exception escaped

15:10:39.817 [ERROR] [org.AwardTracker.AwardTracker] Uncaught exception escaped

java.lang.Error: Unresolved compilation problem: 
Cannot invoke clone() on the array type int[]

at org.AwardTracker.client.BCrypt.crypt_raw(BCrypt.java:609)
at org.AwardTracker.client.BCrypt.hashpw(BCrypt.java:682)
at org.AwardTracker.client.CreateAccountView$1$DuplicateHandler.onSuccess(CreateAccountView.java:103)
at org.AwardTracker.client.CreateAccountView$1$DuplicateHandler.onSuccess(CreateAccountView.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)

根据文档,我包含了 BCrypt.java 和调用 BCypt 并返回值的单行。我没有修改 BCrypt.java。

任何帮助,将不胜感激。

问候,

格林

4

1 回答 1

0

我想在 GWT 中做同样的事情,即我想在客户端使用 BCrypt;不幸的是,java.security 包尚未移植到 GWT,这就是为什么您不能在客户端使用 java.security.SecureRandom 类的原因。一种解决方案是自己移植该类。我的决定是在服务器端使用 BCrypt,并依靠安全套接字 (SSL) 来保护从客户端发送到服务器的密码。可以在此处找到已在 GWT 中的客户端可用的包:JRE 仿真参考

于 2013-01-30T12:24:06.793 回答