示例#1
0
    def get_public_key_breakdown(cls, key):
        """Returns the breakdown of the given public key.

        :param str key: PEM encoded RSA public key.

        :return: Tuple of binary key, modulus and exponent.
        :rtype: (str, str, str)
        """
        # Strip the text part
        if not (key.startswith(cls.PUB_KEY_BEGIN)
                and key.endswith(cls.PUB_KEY_END)):
            raise RuntimeError('Given key is not Public key')
        key = key[len(cls.PUB_KEY_BEGIN):-len(cls.PUB_KEY_END)]

        # Convert to der format
        key_bin = base64.b64decode(key)
        key = nice_binary_to_string(key_bin, sep=' ',
                                    length=len(key_bin)).split(' ')

        # Parse the key
        key_objs = asn1.parse(key)

        # Get the modulus & exponent
        modulus = ' '.join(key_objs[0].value[2].value[0].value)
        exponent = ' '.join(key_objs[0].value[2].value[1].value)

        # return the keys in binary
        return (key_bin, nice_string_to_binary(modulus, sep=' '),
                nice_string_to_binary(exponent, sep=' '))
示例#2
0
 def con_bin_2_list(v):
     return nice_binary_to_string(v, sep=':', length=len(v)).split(':')