setup.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Complete-Bunq-API-Python-Wrapper 作者: PJUllrich 项目源码 文件源码
def create_new_key_pair(self, save_to_config=True):
        """Creates a new public/private key pair and saves them to the config file

        :return: Prints out a success message
        """
        private_key = rsa.generate_private_key(
            public_exponent=65537,
            key_size=2048,
            backend=default_backend()
        )

        private_key_decoded = private_key.private_bytes(
            encoding=serialization.Encoding.PEM,
            format=serialization.PrivateFormat.PKCS8,
            encryption_algorithm=serialization.NoEncryption()
        ).decode()

        public_key_decoded = private_key.public_key().public_bytes(
            encoding=serialization.Encoding.PEM,
            format=serialization.PublicFormat.SubjectPublicKeyInfo
        ).decode()

        print('New key pair was created')

        if save_to_config:
            self.config.set('key_private', private_key_decoded)
            self.config.set('key_public', public_key_decoded)
        else:
            print('\tNew Private Key: %s' % private_key_decoded)
            print('\tNew Public Key:  %s' % public_key_decoded)

        return private_key_decoded, public_key_decoded
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号