Exemplo n.º 1
0
        /// <summary>
        /// Encrypts a zero plaintext with the secret key and stores the result in
        /// destination.
        /// </summary>
        /// <remarks>
        /// The encryption parameters for the resulting ciphertext correspond to the
        /// highest (data) level in the modulus switching chain. Dynamic memory
        /// allocations in the process are allocated from the memory pool pointed to
        /// by the given MemoryPoolHandle.
        ///
        /// Half of the polynomials in relinearization keys are randomly generated
        /// and are replaced with the seed used to compress output size. The output
        /// is in binary format and not human-readable. The output stream must have
        /// the "binary" flag set.
        /// </remarks>
        /// <param name="stream">The stream to save the Ciphertext to</param>
        /// <param name="comprMode">The desired compression mode</param>
        /// <param name="pool">The MemoryPoolHandle pointing to a valid memory
        /// pool</param>
        /// <exception cref="ArgumentNullException">if stream is null</exception>
        /// <exception cref="InvalidOperationException">if a secret key is not
        /// set</exception>
        /// <exception cref="ArgumentException">if the stream is closed or does not
        /// support writing</exception>
        /// <exception cref="IOException">if I/O operations failed</exception>
        /// <exception cref="InvalidOperationException">if compression mode is not
        /// supported, or if compression failed</exception>
        /// <exception cref="ArgumentException">if pool is uninitialized</exception>
        public long EncryptZeroSymmetricSave(
            Stream stream, ComprModeType?comprMode = null,
            MemoryPoolHandle pool = null)
        {
            if (null == stream)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            comprMode = comprMode ?? Serialization.ComprModeDefault;
            if (!Serialization.IsSupportedComprMode(comprMode.Value))
            {
                throw new InvalidOperationException("Unsupported compression mode");
            }

            IntPtr poolHandle = pool?.NativePtr ?? IntPtr.Zero;

            using (Ciphertext destination = new Ciphertext(pool))
            {
                NativeMethods.Encryptor_EncryptZeroSymmetric2(
                    NativePtr, true, destination.NativePtr, poolHandle);

                return(destination.Save(stream, comprMode));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the PublicKey to an output stream.
        /// </summary>
        ///
        /// <remarks>
        /// Saves the PublicKey to an output stream. The output is in binary format and
        /// not human-readable. The output stream must have the "binary" flag set.
        /// </remarks>
        /// <param name="stream">The stream to save the PublicKey to</param>
        /// <exception cref="ArgumentNullException">if stream is null</exception>
        public void Save(Stream stream)
        {
            if (null == stream)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            Data.Save(stream);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Encrypts a zero plaintext with the secret key and stores the result in destination.
        /// </summary>
        /// <remarks>
        /// The encryption parameters for the resulting ciphertext correspond to the
        /// highest (data) level in the modulus switching chain. Dynamic memory allocations in
        /// the process are allocated from the memory pool pointed to by the given MemoryPoolHandle.
        ///
        /// Half of the polynomials in relinearization keys are randomly generated
        /// and are replaced with the seed used to compress output size. The output
        /// is in binary format and not human-readable. The output stream must have
        /// the "binary" flag set.
        /// </remarks>
        /// <param name="stream">The stream to save the Ciphertext to</param>
        /// <param name="comprMode">The desired compression mode</param>
        /// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
        /// <exception cref="ArgumentNullException">if stream is null</exception>
        /// <exception cref="ArgumentException">if pool is uninitialized</exception>
        public long EncryptZeroSymmetricSave(Stream stream, ComprModeType?comprMode = null, MemoryPoolHandle pool = null)
        {
            if (null == stream)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            IntPtr poolHandle = pool?.NativePtr ?? IntPtr.Zero;

            using (Ciphertext destination = new Ciphertext(pool))
            {
                NativeMethods.Encryptor_EncryptZeroSymmetric2(NativePtr, true, destination.NativePtr, poolHandle);
                return(destination.Save(stream, comprMode));
            }
        }