You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EncryptionMode.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.poifs.crypt;
  16. import java.util.function.Supplier;
  17. import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
  18. import org.apache.poi.poifs.crypt.agile.AgileEncryptionInfoBuilder;
  19. import org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4EncryptionInfoBuilder;
  20. import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionInfoBuilder;
  21. import org.apache.poi.poifs.crypt.standard.StandardEncryptionInfoBuilder;
  22. import org.apache.poi.poifs.crypt.xor.XOREncryptionInfoBuilder;
  23. /**
  24. * Office supports various encryption modes.
  25. * The encryption is either based on the whole container ({@link #agile}, {@link #standard} or {@link #binaryRC4})
  26. * or record based ({@link #cryptoAPI}). The record based encryption can't be accessed directly, but will be
  27. * invoked by using the {@link Biff8EncryptionKey#setCurrentUserPassword(String)} before saving the document.
  28. */
  29. public enum EncryptionMode {
  30. /* @see <a href="http://msdn.microsoft.com/en-us/library/dd907466(v=office.12).aspx">2.3.6 Office Binary Document RC4 Encryption</a> */
  31. binaryRC4(BinaryRC4EncryptionInfoBuilder::new, 1, 1, 0x0),
  32. /* @see <a href="http://msdn.microsoft.com/en-us/library/dd905225(v=office.12).aspx">2.3.5 Office Binary Document RC4 CryptoAPI Encryption</a> */
  33. cryptoAPI(CryptoAPIEncryptionInfoBuilder::new, 4, 2, 0x04),
  34. /* @see <a href="http://msdn.microsoft.com/en-us/library/dd906097(v=office.12).aspx">2.3.4.5 \EncryptionInfo Stream (Standard Encryption)</a> */
  35. standard(StandardEncryptionInfoBuilder::new, 4, 2, 0x24),
  36. /* @see <a href="http://msdn.microsoft.com/en-us/library/dd925810(v=office.12).aspx">2.3.4.10 \EncryptionInfo Stream (Agile Encryption)</a> */
  37. agile(AgileEncryptionInfoBuilder::new, 4, 4, 0x40),
  38. /* @see <a href="https://msdn.microsoft.com/en-us/library/dd907599(v=office.12).aspx">XOR Obfuscation</a> */
  39. xor(XOREncryptionInfoBuilder::new, 0, 0, 0)
  40. ;
  41. public final Supplier<EncryptionInfoBuilder> builder;
  42. public final int versionMajor;
  43. public final int versionMinor;
  44. public final int encryptionFlags;
  45. EncryptionMode(Supplier<EncryptionInfoBuilder> builder, int versionMajor, int versionMinor, int encryptionFlags) {
  46. this.builder = builder;
  47. this.versionMajor = versionMajor;
  48. this.versionMinor = versionMinor;
  49. this.encryptionFlags = encryptionFlags;
  50. }
  51. }