def der2pem(der_string, obj='UNKNOWN'):
 pem_string = ('-----BEGIN %s-----\n' % obj)
 base64_string = base64.b64encode(der_string)
 chunks = [base64_string[i:(i + 64)] for i in range(0, len(base64_string), 64)]
 pem_string += '\n'.join(chunks)
 pem_string += ('\n-----END %s-----\n' % obj)
 return pem_string

def der2pem ( der_string , obj = 'UNKNOWN' ) : pem_string = ( '-----BEGIN %s-----\n' % obj ) base64_string = base64 . b64encode ( der_string ) chunks = [ base64_string [ i : ( i + 64 ) ] for i in range ( 0 , len ( base64_string ) , 64 ) ] pem_string += '\n' . join ( chunks ) pem_string += ( '\n-----END %s-----\n' % obj ) return pem_string
encode a byte string in pem format .