def pack(self): """Return the text representation of this message.""" c = self.contents fields = [("Message-type", { 'TXT' : "plaintext", 'LONG' : "overcompressed", 'BIN' : "binary", 'ENC' : "encrypted", 'FRAG' : 'fragment' }[self.messageType]), ] if self.messageType == 'ENC': fields.append(("Decoding-handle", binascii.b2a_base64(self.tag).strip())) return armorText(c, MESSAGE_ARMOR_NAME, headers=fields, base64=(self.messageType!='TXT'))
def _writeEncryptedFile(fname, password, magic, data): """Write 'data' into an encrypted file named 'fname', replacing it if necessary. Encrypts the data with the password 'password', and uses the filetype 'magic'.""" assert len(magic) == MAGIC_LEN prng = getCommonPRNG() length = struct.pack("!L", len(data)) paddingLen = ceilDiv(len(data), 1024)*1024 - len(data) padding = prng.getBytes(paddingLen) data = "".join([length,data,padding]) salt = prng.getBytes(SALT_LEN) key = sha1(salt+password+salt)[:AES_KEY_LEN] digest = sha1("".join([data,salt,magic])) encrypted = ctr_crypt(data+digest, key) contents = "".join([magic,"\x00",salt,encrypted]) writeFile(fname, armorText(contents, "TYPE III KEYRING", [("Version","0.1")]))
def _writeEncryptedFile(fname, password, magic, data): """Write 'data' into an encrypted file named 'fname', replacing it if necessary. Encrypts the data with the password 'password', and uses the filetype 'magic'.""" assert len(magic) == MAGIC_LEN prng = getCommonPRNG() length = struct.pack("!L", len(data)) paddingLen = ceilDiv(len(data), 1024) * 1024 - len(data) padding = prng.getBytes(paddingLen) data = "".join([length, data, padding]) salt = prng.getBytes(SALT_LEN) key = sha1(salt + password + salt)[:AES_KEY_LEN] digest = sha1("".join([data, salt, magic])) encrypted = ctr_crypt(data + digest, key) contents = "".join([magic, "\x00", salt, encrypted]) writeFile(fname, armorText(contents, "TYPE III KEYRING", [("Version", "0.1")]))
def pack(self): """Return the text representation of this message.""" c = self.contents fields = [ ("Message-type", { 'TXT': "plaintext", 'LONG': "overcompressed", 'BIN': "binary", 'ENC': "encrypted", 'FRAG': 'fragment' }[self.messageType]), ] if self.messageType == 'ENC': fields.append( ("Decoding-handle", binascii.b2a_base64(self.tag).strip())) return armorText(c, MESSAGE_ARMOR_NAME, headers=fields, base64=(self.messageType != 'TXT'))
def packAsText(self): """Returns the external text representation of this reply block""" return armorText(self.pack(), RB_ARMOR_NAME, headers=(("Version", "0.2"),))
def packAsText(self): """Returns the external text representation of this reply block""" return armorText(self.pack(), RB_ARMOR_NAME, headers=(("Version", "0.2"), ))