/// <summary> /// Generates and saves relinearization keys to an output stream. /// </summary> /// <remarks> /// 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 relinearization keys to</param> /// <param name="comprMode">The desired compression mode</param> public long RelinKeysSave(Stream stream, ComprModeType?comprMode = null) { NativeMethods.KeyGenerator_RelinKeys(NativePtr, true, out IntPtr relinKeysPtr); using (RelinKeys relinKeys = new RelinKeys(relinKeysPtr)) { return(relinKeys.Save(stream, comprMode)); } }
/// <summary> /// Generates and saves relinearization keys to an output stream. /// </summary> /// <remarks> /// 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 relinearization keys to</param> /// <param name="comprMode">The desired compression mode</param> /// <exception cref="ArgumentNullException">if stream is null</exception> /// <exception cref="InvalidOperationException">if the encryption /// parameters do not support keyswitching</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> public long RelinKeysSave(Stream stream, ComprModeType?comprMode = null) { if (null == stream) { throw new ArgumentNullException(nameof(stream)); } if (!UsingKeyswitching()) { throw new InvalidOperationException("Encryption parameters do not support keyswitching"); } comprMode = comprMode ?? Serialization.ComprModeDefault; if (!Serialization.IsSupportedComprMode(comprMode.Value)) { throw new InvalidOperationException("Unsupported compression mode"); } NativeMethods.KeyGenerator_RelinKeys(NativePtr, true, out IntPtr relinKeysPtr); using (RelinKeys relinKeys = new RelinKeys(relinKeysPtr)) { return(relinKeys.Save(stream, comprMode)); } }