Writes an object ot an encrypted file
541297
public static void serialize(File file, SerializableObject object, @NonNull EncryptionKey encryptionKey) throws IOException {
		ByteArrayOutputStream bos = null;
		DataOutputStream dos = null;
		try {
			bos = new ByteArrayOutputStream();
			dos = new DataOutputStream(bos);
			object.writeExternal(dos);
			final byte[] unencryptedBytes = bos.toByteArray();
			final byte[] encryptedBytes = Encryptor.encrypt(encryptionKey, unencryptedBytes);
			Util.writeAtomically(file, encryptedBytes);
		} catch (Exception e) {
			throw new IOException(e);
		} finally {
			Util.ensureClosed(bos);
			Util.ensureClosed(dos);
		}
	}
77950
private void writeObject(java.io.ObjectOutputStream oos)
        throws java.io.IOException
    {
        if (guard != null)
            guard.checkGuard(object);

        oos.defaultWriteObject();
    }
1372744
private void writeObject(ObjectOutputStream out) throws IOException {
        PutField fields = out.putFields();
        fields.put(AUTH_METHOD, authMethod);
        fields.put(ACCESS_ID, accessId);
        fields.put(SECURITY_NAME, securityName);
        out.writeFields();
    }
833013
def encrypt_file(file, keys=secretKeys()):
    ''''''
    key = keys.encryptKey
    iv = keys.encryptIV
    encData = tempfile.SpooledTemporaryFile(max_size=SPOOL_SIZE, mode='w+b')
    cipher = Cryptodome.Cipher.AES.new(key, Cryptodome.Cipher.AES.MODE_GCM, iv)

    pbar = progbar(fileSize(file))

    for chunk in iter(lambda: file.read(CHUNK_SIZE), b''):
        encData.write(cipher.encrypt(chunk))
        pbar.update(len(chunk))

    pbar.close()
    encData.write(cipher.digest())
    file.close()

    encData.seek(0)
    return encData
1197059
public static void encryptToFile(String path, byte[] buf, String key) {
        try {
            FileOutputStream fos = new FileOutputStream(path);
            fos.write(encrypt(buf, key).getBytes());
            fos.close();
        } catch (final Exception e) {
            logger.warn("Could not encrypt to file {}", path, e);
        }
    }
1347090
public void toPdf(PdfWriter writer, OutputStream os) throws IOException {
        byte b[] = getBytes();
        PdfEncryption crypto = null;
        if (writer != null)
            crypto = writer.getEncryption();
        if (crypto != null && !crypto.isEmbeddedFilesOnly())
            b = crypto.encryptByteArray(b);
        if (hexWriting) {
            ByteBuffer buf = new ByteBuffer();
            buf.append('<');
            int len = b.length;
            for (int k = 0; k < len; ++k)
                buf.appendHex(b[k]);
            buf.append('>');
            os.write(buf.toByteArray());
        }
        else
            os.write(PdfContentByte.escapeString(b));
    }
1202502
function containsEncryptedData(obj) {
    var foundEncrypted = false;
    if (_.isString(obj)) {
        foundEncrypted = isEncrypted(obj);
    } else if (_.isArray(obj)) {
        for (var i = 0; i < obj.length; i++) {
            foundEncrypted = foundEncrypted || containsEncryptedData(obj[i]);
        }
    } else if (_.isObject(obj)) {
        for (var key in obj) {
            foundEncrypted = foundEncrypted || containsEncryptedData(obj[key]);
        }
    }

    return foundEncrypted;
}
214944
def dump(obj, f, preserve=False):
    
    if not f.write:
        raise TypeError('You can only dump an object into a file object')
    encoder = Encoder(f, preserve=preserve)
    return encoder.write_dict(obj)
845389
public void write(ObjectWriter out, PersistedValueData vd) throws IOException
   {
      out.writeInt(SerializationConstants.PERSISTED_VALUE_DATA);
      out.writeInt(vd.getOrderNumber());

      boolean isByteArray = vd.isByteArray();
      out.writeBoolean(isByteArray);

      if (isByteArray)
      {
         byte[] data = vd.getAsByteArray();
         out.writeInt(data.length);
         out.write(data);
      }
      else
      {
         // write file content
         FilePersistedValueData streamed = (FilePersistedValueData)vd;

         InputStream in = null;

         if (streamed.getFile() == null && vd instanceof StreamPersistedValueData)
         {
            if (((StreamPersistedValueData)vd).getTempFile() != null)
            {
               in = PrivilegedFileHelper.fileInputStream(((StreamPersistedValueData)vd).getTempFile());
            }
         }
         else
         {
            in = streamed.getAsStream();
         }

         if (streamed.getFile() instanceof SerializationSpoolFile)
         {
            SerializationSpoolFile ssf = (SerializationSpoolFile)streamed.getFile();
            out.writeString(ssf.getId());
            out.writeLong(0);
         }
         else
         {
            // write property id - used for reread data optimization
            String id = IdGenerator.generate();
            out.writeString(id);

            if (in == null)
            {
               // Deleted state usecase
               out.writeLong(SerializationConstants.NULL_FILE);
            }
            else
            {
               out.writeLong(vd.getLength());
               try
               {
                  byte[] buf = new byte[SerializationConstants.INTERNAL_BUFFER_SIZE];
                  int l = 0;
                  while ((l = in.read(buf)) >= 0)
                  {
                     out.write(buf, 0, l);
                  }
               }
               finally
               {
                  in.close();
               }
            }
         }
      }
   }
1201267
def _write_header(self):
        ''

        header = b'scrypt' + CHR0 + struct.pack('>BII', int(math.log(self.N, 2)), self.r, self.p) + self.salt

        # Add the header checksum to the header
        checksum = hashlib.sha256(header).digest()[:16]
        header += checksum

        # Add the header stream checksum
        self._checksumer = hmac.new(self.key[32:], msg = header, digestmod = hashlib.sha256)
        checksum = self._checksumer.digest()
        header += checksum
        self._checksumer.update(checksum)

        # Write the header
        self._fp.write(header)

        # Prepare the AES engine
        self._crypto = aesctr.AESCounterModeOfOperation(key = self.key[:32])
        #self._crypto = aes(self.key[:32])

        self._done_header = True
771070
def encrpyt_file(self, filename):
        '''
        
        '''
        if not os.path.exists(filename):
            print "Invalid filename %s. Does not exist" % filename
            return

        if self.vault_password is None:
            print "ENV Variable PYANSI_VAULT_PASSWORD not set"
            return

        if self.is_file_encrypted(filename):
            # No need to do anything.
            return

        cipher = 'AES256'
        vaulteditor = VaultEditor(cipher, self.vault_password, filename)
        vaulteditor.encrypt_file()
1274968
public static void write(final PrivateKey privateKey, final @NonNull File file)
		throws IOException
	{
		write(privateKey, new FileOutputStream(file));
	}
815575
def decrypt_file(path, key)
			data = read_file(path)
			decryptedFile = File.new(path, "wb")
			decryptedFile.write(decrypt(data, key))
			decryptedFile.close
		end
63953
def writeObject(self, obj):
        
        log_debug("Writing object of type {0}".format(type(obj).__name__))
        if isinstance(obj, JavaArray):
            # Deserialized Java array
            self.write_array(obj)
        elif isinstance(obj, JavaEnum):
            # Deserialized Java Enum
            self.write_enum(obj)
        elif isinstance(obj, JavaObject):
            # Deserialized Java object
            self.write_object(obj)
        elif isinstance(obj, JavaString):
            # Deserialized String
            self.write_string(obj)
        elif isinstance(obj, JavaClass):
            # Java class
            self.write_class(obj)
        elif obj is None:
            # Null
            self.write_null()
        elif type(obj) is str:
            # String value
            self.write_blockdata(obj)
        else:
            # Unhandled type
            raise RuntimeError(
                "Object serialization of type {0} is not "
                "supported.".format(type(obj))
            )
1319722
public static void writeObjectToFile(File file, Object object) throws IOException {
    FileOutputStream fs = new FileOutputStream(file);
    ObjectOutputStream os = new ObjectOutputStream(fs);
    os.writeObject(object);
    os.close();
  }
494918
def write(temp_object, opts={})
      temp_object.file do |fd|
        File.new.tap do |file|
          file.metadata = temp_object.meta
          file.data     = fd
          file.save!
          return file.id.to_s
        end
      end
    end
474054
def encrypt_file(self,
                     path,
                     output_path=None,
                     overwrite=False,
                     enable_verbose=True):
        
        path, output_path = files.process_dst_overwrite_args(
            src=path, dst=output_path, overwrite=overwrite,
            src_to_dst_func=files.get_encrpyted_path,
        )

        with open(path, "rb") as infile, open(output_path, "wb") as outfile:
            encrypt_bigfile(infile, outfile, self.his_pubkey)