congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
CipherOutputStream.write
Code IndexAdd Tabnine to your IDE (free)

How to use
write
method
in
javax.crypto.CipherOutputStream

Best Java code snippets using javax.crypto.CipherOutputStream.write (Showing top 20 results out of 576)

origin: apache/incubator-dubbo

@Override
public void write(byte[] buffer, int offset, int length)
    throws IOException {
  _cipherOut.write(buffer, offset, length);
}
origin: apache/incubator-dubbo

@Override
public void write(int ch)
    throws IOException {
  _cipherOut.write(ch);
}
origin: apache/incubator-gobblin

@Override
public void write(int b)
  throws IOException {
 writeHeaderIfNecessary();
 encryptedStream.write(b);
}
origin: apache/incubator-gobblin

@Override
public void write(byte[] b, int off, int len)
  throws IOException {
 writeHeaderIfNecessary();
 encryptedStream.write(b, off, len);
}
origin: apache/incubator-gobblin

@Override
public void write(byte[] b)
  throws IOException {
 writeHeaderIfNecessary();
 encryptedStream.write(b);
}
origin: jenkinsci/jenkins

/**
 * Persists the payload of {@link ConfidentialKey} to the disk.
 */
@Override
protected void store(ConfidentialKey key, byte[] payload) throws IOException {
  try {
    Cipher sym = Secret.getCipher("AES");
    sym.init(Cipher.ENCRYPT_MODE, masterKey);
    try (OutputStream fos = Files.newOutputStream(getFileFor(key).toPath());
       CipherOutputStream cos = new CipherOutputStream(fos, sym)) {
      cos.write(payload);
      cos.write(MAGIC);
    }
  } catch (GeneralSecurityException e) {
    throw new IOException("Failed to persist the key: "+key.getId(),e);
  } catch (InvalidPathException e) {
    throw new IOException(e);
  }
}
origin: stackoverflow.com

 SecretKeySpec skeySpec = new SecretKeySpec(y.getBytes(), "AES");

FileInputStream fis;
FileOutputStream fos;
CipherOutputStream cos;
// File you are reading from
fis = new FileInputStream("/tmp/a.txt");
// File output
fos = new FileOutputStream("/tmp/b.txt");

// Here the file is encrypted. The cipher1 has to be created.
// Key Length should be 128, 192 or 256 bit => i.e. 16 byte
SecretKeySpec skeySpec = new SecretKeySpec("MyDifficultPassw".getBytes(), "AES"); 
Cipher cipher1 = Cipher.getInstance("AES");  
cipher1.init(Cipher.ENCRYPT_MODE, skeySpec);
cos = new CipherOutputStream(fos, cipher1);
// Here you read from the file in fis and write to cos.
byte[] b = new byte[8];
int i = fis.read(b);
while (i != -1) {
  cos.write(b, 0, i);
  i = fis.read(b);
}
cos.flush();
origin: stackoverflow.com

 static void encrypt() throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
  // Here you read the cleartext.
  FileInputStream fis = new FileInputStream("data/cleartext");
  // This stream write the encrypted text. This stream will be wrapped by another stream.
  FileOutputStream fos = new FileOutputStream("data/encrypted");

  // Length is 16 byte
  // Careful when taking user input!!! http://stackoverflow.com/a/3452620/1188357
  SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(), "AES");
  // Create cipher
  Cipher cipher = Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE, sks);
  // Wrap the output stream
  CipherOutputStream cos = new CipherOutputStream(fos, cipher);
  // Write bytes
  int b;
  byte[] d = new byte[8];
  while((b = fis.read(d)) != -1) {
    cos.write(d, 0, b);
  }
  // Flush and close streams.
  cos.flush();
  cos.close();
  fis.close();
}
origin: syncany/syncany

private static byte[] encryptWithAesGcm(byte[] plaintext, byte[] randomKeyBytes, byte[] randomIvBytes) throws IOException, InvalidKeyException,
    InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException {
  SecretKey randomKey = new SecretKeySpec(randomKeyBytes, "AES");
  
  Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
  cipher.init(Cipher.ENCRYPT_MODE, randomKey, new IvParameterSpec(randomIvBytes));
  
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  CipherOutputStream cipherOutputStream = new CipherOutputStream(byteArrayOutputStream, cipher);
  
  cipherOutputStream.write(plaintext);
  cipherOutputStream.close();
  
  return byteArrayOutputStream.toByteArray();
}

origin: stackoverflow.com

  new CipherOutputStream(
    new FileOutputStream(encryptedDataFilePath), inCipher);
cipherOutputStream.write(plainText.getBytes("UTF-8"));
cipherOutputStream.close();
origin: apache/accumulo

/**
 * Override of CipherOutputStream's write to count the number of bytes that have been encrypted.
 * This method now throws an exception if an attempt to write bytes beyond a maximum is made.
 */
@Override
public void write(byte b[], int off, int len) throws IOException {
 count += len;
 if (count > maxOutputSize) {
  throw new IOException("Attempt to write " + count + " bytes was made. A maximum of "
    + maxOutputSize + " is allowed for an encryption stream.");
 }
 super.write(b, off, len);
}
origin: apache/accumulo

 /**
  * Override of CipherOutputStream's write for a single byte to count it. This method now throws an
  * exception if an attempt to write bytes beyond a maximum is made.
  */
 @Override
 public void write(int b) throws IOException {
  count++;
  if (count > maxOutputSize) {
   throw new IOException("Attempt to write " + count + " bytes was made. A maximum of "
     + maxOutputSize + " is allowed for an encryption stream.");
  }
  super.write(b);
 }
}
origin: structr/structr

private static byte[] encryptBlocks(final byte[] data, final Cipher cipher, final int dataSize) throws IOException {
  final ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
  final int count                 = (data.length / dataSize) + 1;
  int remaining                   = data.length;
  for (int i=0; i<count; i++) {
    final int offset = i*dataSize;
    final int length = Math.min(dataSize, remaining);
    final CipherOutputStream cos = new CipherOutputStream(bos, cipher);
    cos.write(data, offset, length);
    cos.flush();
    cos.close();
    remaining -= length;
  }
  return bos.toByteArray();
}
origin: stackoverflow.com

while((read=encfis.read())!=-1)
  cos.write(read);
  cos.flush();
origin: com.alibaba/dubbo

@Override
public void write(int ch)
    throws IOException {
  _cipherOut.write(ch);
}
origin: com.alibaba/dubbo

@Override
public void write(byte[] buffer, int offset, int length)
    throws IOException {
  _cipherOut.write(buffer, offset, length);
}
origin: cloudant/sync-android

  @Override
  /**
   * <p>Writes the specified byte to this output stream.</p>
   *
   * <p>This just proxies to the underlying CipherOutputStream.</p>
   *
   * @param b the data
   */
  public void write(int b) throws IOException {
    cipherOutputStream.write(b);
  }
}
origin: com.caucho/com.springsource.com.caucho

public void write(byte []buffer, int offset, int length)
 throws IOException
{
 _cipherOut.write(buffer, offset, length);
}
origin: com.linkedin.gobblin/gobblin-crypto

@Override
public void write(byte[] b)
  throws IOException {
 writeHeaderIfNecessary();
 encryptedStream.write(b);
}
origin: com.caucho/com.springsource.com.caucho

public void write(int ch)
 throws IOException
{
 _cipherOut.write(ch);
}

javax.cryptoCipherOutputStreamwrite

Javadoc

Writes the single byte to this cipher output stream.

Popular methods of CipherOutputStream

  • <init>
    Creates a new CipherOutputStream instance for an OutputStream and a Cipher.
  • close
    Close this cipher output stream. On the underlying cipher doFinal will be invoked, and any buffered
  • flush
    Flushes this cipher output stream.

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • addToBackStack (FragmentTransaction)
  • notifyDataSetChanged (ArrayAdapter)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • Kernel (java.awt.image)
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now