3 Replies Latest reply on May 15, 2014 11:42 PM by Wind Wild

    RSA Encryption Exception on wildfly-8.0.0.Final

    Wind Wild Newbie

      Hi everyone

      Today,I want to use RSA funtion to encrypt a word,I encrypt it twice in the controller as following:

      @Controller
      public class IndexController {
          
          @RequestMapping("index")
          public String index(){
              AsymmetricCoder rsa = AsymmetricCoderFactory.getAsymmetricCoder("RSA");
              String serverStr = "RSACoding";
              String clientStr = "RSACoding";
              String publicKey = null;
              System.out.println("server's context:" + serverStr);
              System.out.println("client's context:" + clientStr);
              String seed = "test";
              Map<String, Object> keyMap;
              try {
                  keyMap = rsa.initKey(seed);
                  publicKey = rsa.getPublicKey(keyMap);
                  byte[] client_public_str = rsa.encryptByPublicKey(clientStr.getBytes(), publicKey);
                  byte[] server_public_str = rsa.encryptByPublicKey(serverStr.getBytes(), publicKey);
                  BigInteger newClientStr = new BigInteger(client_public_str);   
                  System.out.println("client's codedContext:" + newClientStr.toString(16));
                  BigInteger newServerStr = new BigInteger(server_public_str);   
                  System.out.println("server's codedContext:" + newServerStr.toString(16));
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              return "index.ftl";
          }
      }
      

      The value of serverStr and clientStr are the same,they are both "RSACoding".

      when i deploy this project to wildfly-8.0.0.Final and "index" controller,the server.log show message as following:

      rsawildfly.jpg

      because the value of serverStr and clientStr are the same,after use RSA Encrypties them,the Encryption context should be different,but above picture show that client's codedContext is same as server's codedContext.

      when i deploy on tomcat 7 and jboss as 7,the server log as following:

      tomcat 7:

      rsatomcat.jpg

      jboss'

      jboss as 7:

      rsajboss7.jpg

      We can see that client's codedContext and server's codedContext are different,it's normally.

      So i suspect this is a bug on wildfly-8.0.0.Final,who can tell me how to resolve this problem?

      Thanks!