title: Simple RSA encrypt and decrypt message in JAVA
body: <p>I have been trying for couple of days and simply can't make it work. If I have a private and public key pair. I am just trying to encrypt a message using public key and then decrypt using private key. My code looks something like this:</p>
  
  <pre><code>    String message = "Secure Message";
      KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
      keyPairGenerator.initialize(2048);
  
      KeyPair keyPair = keyPairGenerator.generateKeyPair();
  
      Key privateKey = keyPair.getPrivate();
      Key publicKey = keyPair.getPublic();
  
      Cipher cipher = Cipher.getInstance(publicKey.getAlgorithm());
  
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);
  
      byte[] encryptData = cipher.doFinal(message.getBytes());
  
      cipher.init(Cipher.DECRYPT_MODE, privateKey);
  
      byte[] decryptData = cipher.doFinal(encryptData);
  
      System.out.println(encryptData.toString());
      System.out.println(decryptData.toString());
  </code></pre>
  
  <p>But it doesn't seem to be working. Output I get is something like this:</p>
  
  <pre><code>    [B@4e33967b
      [B@1cdc8d59
  </code></pre>