000026132 - How to use writePKCS8PrivateKey in the CertUtilities.java file; how to load a PKCS #8 private key that was previously written using the writePKCS8PrivateKey

Document created by RSA Customer Support Employee on Jun 16, 2016Last modified by RSA Customer Support Employee on Apr 21, 2017
Version 2Show Document
  • View in full screen mode

Article Content

Article Number000026132
Applies ToRSA BSAFE Cert-J 1.0
IssueHow to use writePKCS8PrivateKey in the CertUtilities.java file; how to load a PKCS #8 private key that was previously written using the writePKCS8PrivateKey
The following error occurs: com.rsa.jsafe.JSAFE_InvalidUseException: Could not perform unpadding: invalid pad byte
CauseA bug in the writePKCS8PrivateKey in the sample CertUtilities.java file
ResolutionIn the PKCS8PrivateKey function change the lines:

      char[] password = new char[20];
      String response = caller.getResponse("Enter private key password");
      response.getChars
          (0, (response.length() > 20 ? 20 : response.length ()),
             password, 0);
      key.setPassword (password, 0, password.length); 
                   
with:

     String response = caller.getResponse("Enter private key password");
     char[] password = new char[response.length()];
     response.getChars (0, response.length(), password, 0);
     key.setPassword (password, 0, password.length);
Legacy Article IDa654

Attachments

    Outcomes