Esempio n. 1
0
 public virtual byte[] Update(byte[] b, int off, int len)
 {
     if (initiated)
     {
         return(cipher.Update(b, off, len));
     }
     else
     {
         int left = Math.Min(iv.Length - ivptr, len);
         Array.Copy(b, off, iv, ivptr, left);
         off   += left;
         len   -= left;
         ivptr += left;
         if (ivptr == iv.Length)
         {
             cipher    = new AESCipher(false, key, iv);
             initiated = true;
             if (len > 0)
             {
                 return(cipher.Update(b, off, len));
             }
         }
         return(null);
     }
 }
 /// <summary>
 /// Creates a new instance of
 /// <see cref="OutputStreamAesEncryption"/>
 /// </summary>
 /// <param name="out">
 /// the
 /// <see cref="System.IO.Stream"/>
 /// instance to be used as the destination for the encrypted content
 /// </param>
 /// <param name="key">the byte array containing the key for encryption</param>
 /// <param name="off">offset of the key in the byte array</param>
 /// <param name="len">the length of the key in the byte array</param>
 public OutputStreamAesEncryption(Stream @out, byte[] key, int off, int len)
     : base(@out)
 {
     byte[] iv   = IVGenerator.GetIV();
     byte[] nkey = new byte[len];
     Array.Copy(key, off, nkey, 0, len);
     cipher = new AESCipher(true, nkey, iv);
     try {
         Write(iv);
     }
     catch (System.IO.IOException e) {
         throw new PdfException(PdfException.PdfEncryption, e);
     }
 }