net.lingala.zip4j.core.ZipFile.setPassword()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中net.lingala.zip4j.core.ZipFile.setPassword()方法的一些代码示例,展示了ZipFile.setPassword()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipFile.setPassword()方法的具体详情如下:
包路径:net.lingala.zip4j.core.ZipFile
类名称:ZipFile
方法名:setPassword

ZipFile.setPassword介绍

[英]Sets the password for the zip file.
Note: For security reasons, usage of this method is discouraged. Use setPassword(char[]) instead. As strings are immutable, they cannot be wiped out from memory explicitly after usage. Therefore, usage of Strings to store passwords is discouraged. More info here: http://docs.oracle.com/javase/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBEEx
[中]设置zip文件的密码。
注意:出于安全原因,不鼓励使用此方法。改用setPassword(char[])。由于字符串是不可变的,所以在使用后无法明确地从内存中删除它们。因此,不鼓励使用字符串存储密码。更多信息请点击此处:http://docs.oracle.com/javase/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBEEx

代码示例

代码示例来源:origin: net.lingala.zip4j/zip4j

/**
 * Sets the password for the zip file.<br>
 * <b>Note</b>: For security reasons, usage of this method is discouraged. Use 
 * setPassword(char[]) instead. As strings are immutable, they cannot be wiped
 * out from memory explicitly after usage. Therefore, usage of Strings to store 
 * passwords is discouraged. More info here: 
 * http://docs.oracle.com/javase/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBEEx
 * @param password
 * @throws ZipException
 */
public void setPassword(String password) throws ZipException {
  if (!Zip4jUtil.isStringNotNullAndNotEmpty(password)) {
    throw new NullPointerException();
  }
  setPassword(password.toCharArray());
}

代码示例来源:origin: com.github.axet/zip4j

/**
 * Sets the password for the zip file.<br>
 * <b>Note</b>: For security reasons, usage of this method is discouraged. Use 
 * setPassword(char[]) instead. As strings are immutable, they cannot be wiped
 * out from memory explicitly after usage. Therefore, usage of Strings to store 
 * passwords is discouraged. More info here: 
 * http://docs.oracle.com/javase/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBEEx
 * @param password
 * @throws ZipException
 */
public void setPassword(String password) throws ZipException {
  if (!Zip4jUtil.isStringNotNullAndNotEmpty(password)) {
    throw new NullPointerException();
  }
  setPassword(password.toCharArray());
}

代码示例来源:origin: org.jboss.forge.addon/resources-impl

@Override
public ZipFileResource setPassword(char[] password)
{
 try
 {
   getZipFile().setPassword(password);
 }
 catch (ZipException e)
 {
   throw new ResourceException("Error while setting the zip password", e);
 }
 return this;
}

代码示例来源:origin: de.alpharogroup/file-worker

/**
 * Extract.
 *
 * @param zipFile4j
 *            the zip file4j
 * @param destination
 *            the destination
 * @param password
 *            the password
 * @throws ZipException
 *             the zip exception
 */
public static void extract(final ZipFile zipFile4j, final File destination,
  final String password) throws ZipException
{
  if (zipFile4j.isEncrypted())
  {
    zipFile4j.setPassword(password);
  }
  zipFile4j.extractAll(destination.getAbsolutePath());
}

代码示例来源:origin: SpringCloud/spring-cloud-codegen

throw new ZipException("Password can't be empty with encryption mode");
zFile.setPassword(password.toCharArray());

代码示例来源:origin: Nepxion/Skeleton

throw new ZipException("Password can't be empty with encryption mode");
zFile.setPassword(password.toCharArray());

代码示例来源:origin: jclehner/rxdroid

public boolean restore(String password)
  {
    if(!isValid())
      throw new IllegalStateException("Invalid backup file");
    synchronized(Database.LOCK_DATA)
    {
      try
      {
        if(password != null)
          mZip.setPassword(password);
        mZip.extractAll(RxDroid.getPackageInfo().applicationInfo.dataDir);
      }
      catch(ZipException e)
      {
        final String msg = e.getMessage();
        if(password != null && msg.toLowerCase(Locale.US).contains("password"))
          return false;
        throw new WrappedCheckedException(e);
      }
      Settings.init(true);
    }
    NotificationReceiver.rescheduleAlarmsAndUpdateNotification(false);
    return true;
  }
}

代码示例来源:origin: com.jalalkiswani/jk-util

/**
 * Decompress.
 *
 * @param sourceZipFilePath
 *            the source zip file path
 * @param extractedZipFilePath
 *            the extracted zip file path
 * @param password
 *            the password
 */
public void decompress(String sourceZipFilePath, String extractedZipFilePath, String password) {
  try {
    ZipFile zipFile = new ZipFile(sourceZipFilePath);
    if (zipFile.isEncrypted()) {
      zipFile.setPassword(password);
    }
    zipFile.extractAll(extractedZipFilePath);
  } catch (Exception e) {
    JKExceptionUtil.handle(e);
  }
}

代码示例来源:origin: MCMrARM/revolution-irc

zipFile.setPassword(password);

相关文章