keystore.py 文件源码

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

项目:delta-sdk-python 作者: Covata 项目源码 文件源码
def __save(self, private_key, file_name):
        if not isinstance(private_key, RSAPrivateKey):
            raise TypeError("private_key must be an instance of RSAPrivateKey, "
                            "actual: {}".format(type(private_key).__name__))

        pem = private_key.private_bytes(
            serialization.Encoding.PEM,
            serialization.PrivateFormat.PKCS8,
            serialization.BestAvailableEncryption(self.__key_store_passphrase))

        file_path = os.path.join(self.key_store_path, file_name)
        if not os.path.isdir(self.key_store_path):
            os.makedirs(self.key_store_path)

        if os.path.isfile(file_path):
            msg = "Save failed: A key with name [{}] already exists".format(
                file_name)
            raise IOError(msg)

        with open(file_path, 'w') as f:
            f.write(pem.decode(encoding='utf8'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号