hudson.model.Hudson.getSecretKeyAsAES128()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(148)

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

Hudson.getSecretKeyAsAES128介绍

[英]Gets #getSecretKey() as a key for AES-128.
[中]获取#getSecretKey()作为AES-128的密钥。

代码示例

代码示例来源:origin: hudson/hudson-2.x

/**
 * Turns {@link Hudson#getSecretKey()} into an AES key. 
 */
private static SecretKey getKey() throws UnsupportedEncodingException, GeneralSecurityException {
  String secret = SECRET;
  if(secret==null)    return Hudson.getInstance().getSecretKeyAsAES128();
  return Util.toAes128Key(secret);
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Turns {@link Hudson#getSecretKey()} into an AES key. 
 */
private static SecretKey getKey() throws UnsupportedEncodingException, GeneralSecurityException {
  String secret = SECRET;
  if(secret==null)    return Hudson.getInstance().getSecretKeyAsAES128();
  return Util.toAes128Key(secret);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Turns {@link Hudson#getSecretKey()} into an AES key.
 */
private static SecretKey getKey() throws UnsupportedEncodingException, GeneralSecurityException {
  String secret = SECRET;
  if (secret == null) {
    return Hudson.getInstance().getSecretKeyAsAES128();
  }
  return Util.toAes128Key(secret);
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Turns {@link Hudson#getSecretKey()} into an AES key. 
 */
private static SecretKey getKey() throws UnsupportedEncodingException, GeneralSecurityException {
  String secret = SECRET;
  if(secret==null)    return Hudson.getInstance().getSecretKeyAsAES128();
  return Util.toAes128Key(secret);
}

代码示例来源:origin: hudson/hudson-2.x

private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
  try {
    String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null;
    if (base64!=null) {
      Cipher sym = Secret.getCipher("AES");
      sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
      ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(
          new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)),
          Hudson.getInstance().pluginManager.uberClassLoader);
      long timestamp = ois.readLong();
      if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp))
        // don't deserialize something too old to prevent a replay attack
        return (ConsoleAnnotator)ois.readObject();
    }
  } catch (GeneralSecurityException e) {
    throw new IOException2(e);
  } catch (ClassNotFoundException e) {
    throw new IOException2(e);
  }
  // start from scratch
  return ConsoleAnnotator.initial(context==null ? null : context.getClass());
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
  try {
    String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null;
    if (base64!=null) {
      Cipher sym = Secret.getCipher("AES");
      sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
      ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(
          new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)),
          Hudson.getInstance().pluginManager.uberClassLoader);
      long timestamp = ois.readLong();
      if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp))
        // don't deserialize something too old to prevent a replay attack
        return (ConsoleAnnotator)ois.readObject();
    }
  } catch (GeneralSecurityException e) {
    throw new IOException2(e);
  } catch (ClassNotFoundException e) {
    throw new IOException2(e);
  }
  // start from scratch
  return ConsoleAnnotator.initial(context==null ? null : context.getClass());
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
  try {
    String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null;
    if (base64!=null) {
      Cipher sym = Secret.getCipher("AES");
      sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
      ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(
          new CipherInputStream(new ByteArrayInputStream(Base64.decodeBase64(base64)),sym)),
          Hudson.getInstance().pluginManager.uberClassLoader);
      long timestamp = ois.readLong();
      if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp))
        // don't deserialize something too old to prevent a replay attack
        return (ConsoleAnnotator)ois.readObject();
    }
  } catch (GeneralSecurityException e) {
    throw new IOException2(e);
  } catch (ClassNotFoundException e) {
    throw new IOException2(e);
  }
  // start from scratch
  return ConsoleAnnotator.initial(context==null ? null : context.getClass());
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

public long writeHtmlTo(long start, Writer w) throws IOException {
  ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(
      w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
  long r = super.writeLogTo(start,caw);
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Cipher sym = Secret.getCipher("AES");
    sym.init(Cipher.ENCRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
    ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym)));
    oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
    oos.writeObject(caw.getConsoleAnnotator());
    oos.close();
    StaplerResponse rsp = Stapler.getCurrentResponse();
    if (rsp!=null)
      rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encodeBase64(baos.toByteArray())));
  } catch (GeneralSecurityException e) {
    throw new IOException2(e);
  }
  return r;
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

public long writeHtmlTo(long start, Writer w) throws IOException {
  ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(
      w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
  long r = super.writeLogTo(start,caw);
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Cipher sym = Secret.getCipher("AES");
    sym.init(Cipher.ENCRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
    ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym)));
    oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
    oos.writeObject(caw.getConsoleAnnotator());
    oos.close();
    StaplerResponse rsp = Stapler.getCurrentResponse();
    if (rsp!=null)
      rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
  } catch (GeneralSecurityException e) {
    throw new IOException2(e);
  }
  return r;
}

代码示例来源:origin: hudson/hudson-2.x

public long writeHtmlTo(long start, Writer w) throws IOException {
  ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(
      w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
  long r = super.writeLogTo(start,caw);
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Cipher sym = Secret.getCipher("AES");
    sym.init(Cipher.ENCRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
    ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym)));
    oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
    oos.writeObject(caw.getConsoleAnnotator());
    oos.close();
    StaplerResponse rsp = Stapler.getCurrentResponse();
    if (rsp!=null)
      rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
  } catch (GeneralSecurityException e) {
    throw new IOException2(e);
  }
  return r;
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
  ObjectInputStream ois = null;
  try {
    String base64 = req != null ? req.getHeader("X-ConsoleAnnotator") : null;
    if (base64 != null) {
      Cipher sym = Secret.getCipher("AES");
      sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
      ois = new ObjectInputStreamEx(new GZIPInputStream(
          new CipherInputStream(new ByteArrayInputStream(Base64.decodeBase64(base64)), sym)),
          Hudson.getInstance().pluginManager.uberClassLoader);
      long timestamp = ois.readLong();
      if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis() - timestamp)) // don't deserialize something too old to prevent a replay attack
      {
        return (ConsoleAnnotator) ois.readObject();
      }
    }
  } catch (GeneralSecurityException e) {
    throw new IOException2(e);
  } catch (ClassNotFoundException e) {
    throw new IOException2(e);
  } finally {
    IOUtils.closeQuietly(ois);
  }
  // start from scratch
  return ConsoleAnnotator.initial(context == null ? null : context.getClass());
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

public long writeHtmlTo(long start, Writer w) throws IOException {
    ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(
        w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
    long r = super.writeLogTo(start, caw);

    ObjectOutputStream oos = null;
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      Cipher sym = Secret.getCipher("AES");
      sym.init(Cipher.ENCRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
      try {
        oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym)));
        oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
        oos.writeObject(caw.getConsoleAnnotator());
      } finally {
        IOUtils.closeQuietly(oos);
      }
      StaplerResponse rsp = Stapler.getCurrentResponse();
      if (rsp != null) {
        rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encodeBase64(baos.toByteArray())));
      }
    } catch (GeneralSecurityException e) {
      throw new IOException2(e);
    }
    return r;
  }
}

相关文章

Hudson类方法