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.

Encryptor.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.io.IOException;
  17. import java.io.OutputStream;
  18. import java.security.GeneralSecurityException;
  19. import javax.crypto.SecretKey;
  20. import org.apache.poi.poifs.filesystem.DirectoryNode;
  21. import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
  22. import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
  23. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  24. public abstract class Encryptor {
  25. protected static final String DEFAULT_POIFS_ENTRY = Decryptor.DEFAULT_POIFS_ENTRY;
  26. private SecretKey secretKey;
  27. /**
  28. * Return a output stream for encrypted data.
  29. *
  30. * @param dir the node to write to
  31. * @return encrypted stream
  32. */
  33. public abstract OutputStream getDataStream(DirectoryNode dir)
  34. throws IOException, GeneralSecurityException;
  35. // for tests
  36. public abstract void confirmPassword(String password, byte keySpec[], byte keySalt[], byte verifier[], byte verifierSalt[], byte integritySalt[]);
  37. public abstract void confirmPassword(String password);
  38. public static Encryptor getInstance(EncryptionInfo info) {
  39. return info.getEncryptor();
  40. }
  41. public OutputStream getDataStream(NPOIFSFileSystem fs) throws IOException, GeneralSecurityException {
  42. return getDataStream(fs.getRoot());
  43. }
  44. public OutputStream getDataStream(OPOIFSFileSystem fs) throws IOException, GeneralSecurityException {
  45. return getDataStream(fs.getRoot());
  46. }
  47. public OutputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException {
  48. return getDataStream(fs.getRoot());
  49. }
  50. public SecretKey getSecretKey() {
  51. return secretKey;
  52. }
  53. protected void setSecretKey(SecretKey secretKey) {
  54. this.secretKey = secretKey;
  55. }
  56. }