public static String encode(PemInfo pemInfo){
  StringBuffer sbPem=new StringBuffer();
  sbPem.append("-----BEGIN ");
  sbPem.append(pemInfo.getType());
  sbPem.append("-----");
  sbPem.append("\n");
  PemAttributes attributes=pemInfo.getAttributes();
  if (attributes != null && attributes.size() > 0) {
    for (    PemAttribute attribute : attributes.values()) {
      sbPem.append(attribute);
      sbPem.append('\n');
    }
    sbPem.append('\n');
  }
  String base64=new String(Base64.encode(pemInfo.getContent()));
  for (int i=0; i < base64.length(); i+=MAX_PRINTABLE_ENCODING_LINE_LENGTH) {
    int lineLength;
    if (i + MAX_PRINTABLE_ENCODING_LINE_LENGTH > base64.length()) {
      lineLength=base64.length() - i;
    }
 else {
      lineLength=MAX_PRINTABLE_ENCODING_LINE_LENGTH;
    }
    sbPem.append(base64.substring(i,i + lineLength));
    sbPem.append("\n");
  }
  sbPem.append("-----END ");
  sbPem.append(pemInfo.getType());
  sbPem.append("-----");
  sbPem.append("\n");
  return sbPem.toString();
}

public static String encode ( PemInfo pemInfo ) { StringBuffer sbPem = new StringBuffer ( ) ; sbPem . append ( "-----BEGIN " ) ; sbPem . append ( pemInfo . getType ( ) ) ; sbPem . append ( "-----" ) ; sbPem . append ( "\n" ) ; PemAttributes attributes = pemInfo . getAttributes ( ) ; if ( attributes != null && attributes . size ( ) > 0 ) { for ( PemAttribute attribute : attributes . values ( ) ) { sbPem . append ( attribute ) ; sbPem . append ( '\n' ) ; } sbPem . append ( '\n' ) ; } String base64 = new String ( Base64 . encode ( pemInfo . getContent ( ) ) ) ; for ( int i = 0 ; i < base64 . length ( ) ; i += MAX_PRINTABLE_ENCODING_LINE_LENGTH ) { int lineLength ; if ( i + MAX_PRINTABLE_ENCODING_LINE_LENGTH > base64 . length ( ) ) { lineLength = base64 . length ( ) - i ; } else { lineLength = MAX_PRINTABLE_ENCODING_LINE_LENGTH ; } sbPem . append ( base64 . substring ( i , i + lineLength ) ) ; sbPem . append ( "\n" ) ; } sbPem . append ( "-----END " ) ; sbPem . append ( pemInfo . getType ( ) ) ; sbPem . append ( "-----" ) ; sbPem . append ( "\n" ) ; return sbPem . toString ( ) ; }
encode the supplied information as pem .
