code: public static byte[] convert(char[] password, ToBytesMode mode)
      {
          byte[] passwd;
  
          switch (mode) {
              case PKCS12:
                  passwd = PBEParametersGenerator.PKCS12PasswordToBytes(password);
                  break;
              case PKCS5:
                  passwd = PBEParametersGenerator.PKCS5PasswordToBytes(password);
                  break;
              default:
                  passwd = PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password);
                  break;
          }
  
          return passwd;
      }
docs: Convert password to bytes.
  
  @param password password to convert.
  @param mode mode of conversion.
  @return a bytes array representing the password.