コード例 #1
0
 def loadCredentials(self):
     credentials_file = self.credentialsRotatingFile.openLast()
     try:
         encrypted_json = json.load(credentials_file, "utf8")
     except ValueError:
         self.credentials = {}
         return
     aes = Aes()
     aes.setIv(encrypted_json["iv"])
     aes.setKeyByMacAddress()
     credentials_json = aes.decryptBase64ToUnicode(
         encrypted_json["encrypted_credentials"])
     self.credentials = json.loads(credentials_json)
コード例 #2
0
    def saveCredentials(self):
        self.credentialsRotatingFile.rotate()
        credentials_json = json.dumps(self.credentials)
        assert isinstance(credentials_json, str)
        aes = Aes()
        aes.setIv()
        aes.setKeyByMacAddress()
        encrypted_credentials = aes.encryptStrToBase64(credentials_json)

        d = aes.decryptBase64ToUnicode(encrypted_credentials)
        assert credentials_json == d

        encrypted_json_object = {
            "iv": aes.getIv(),
            "encrypted_credentials": encrypted_credentials
        }
        encrypted_json_str = json.dumps(encrypted_json_object)
        assert isinstance(encrypted_json_str, str)
        assert len(encrypted_json_str) > 0
        credentials_file = self.credentialsRotatingFile.openLast()
        credentials_file.write(encrypted_json_str)
        credentials_file.close()
コード例 #3
0
 def loadCredentials(self):
     credentials_file = self.credentialsRotatingFile.openLast()
     try:
         encrypted_json = json.load(credentials_file, "utf8")
     except ValueError:
         self.credentials = {}
         return
     aes = Aes()
     aes.setIv(encrypted_json["iv"])
     aes.setKeyByMacAddress()
     credentials_json = aes.decryptBase64ToUnicode(encrypted_json["encrypted_credentials"])
     self.credentials = json.loads(credentials_json)
コード例 #4
0
    def saveCredentials(self):
        self.credentialsRotatingFile.rotate()
        credentials_json = json.dumps(self.credentials)
        assert isinstance(credentials_json, str)
        aes = Aes()
        aes.setIv()
        aes.setKeyByMacAddress()
        encrypted_credentials = aes.encryptStrToBase64(credentials_json)
        
        d = aes.decryptBase64ToUnicode(encrypted_credentials)
        assert credentials_json == d

        encrypted_json_object = {"iv": aes.getIv(), "encrypted_credentials": encrypted_credentials}
        encrypted_json_str = json.dumps(encrypted_json_object)
        assert isinstance(encrypted_json_str, str)
        assert len(encrypted_json_str) > 0
        credentials_file = self.credentialsRotatingFile.openLast()
        credentials_file.write(encrypted_json_str)
        credentials_file.close()