예제 #1
0
파일: PemReader.java 프로젝트: 289/netty
  static ByteBuf[] readCertificates(File file) throws CertificateException {
    String content;
    try {
      content = readContent(file);
    } catch (IOException e) {
      throw new CertificateException("failed to read a file: " + file, e);
    }

    List<ByteBuf> certs = new ArrayList<ByteBuf>();
    Matcher m = CERT_PATTERN.matcher(content);
    int start = 0;
    for (; ; ) {
      if (!m.find(start)) {
        break;
      }

      ByteBuf base64 = Unpooled.copiedBuffer(m.group(1), CharsetUtil.US_ASCII);
      ByteBuf der = Base64.decode(base64);
      base64.release();
      certs.add(der);

      start = m.end();
    }

    if (certs.isEmpty()) {
      throw new CertificateException("found no certificates: " + file);
    }

    return certs.toArray(new ByteBuf[certs.size()]);
  }
예제 #2
0
파일: PemReader.java 프로젝트: 289/netty
  static ByteBuf readPrivateKey(File file) throws KeyException {
    String content;
    try {
      content = readContent(file);
    } catch (IOException e) {
      throw new KeyException("failed to read a file: " + file, e);
    }

    Matcher m = KEY_PATTERN.matcher(content);
    if (!m.find()) {
      throw new KeyException("found no private key: " + file);
    }

    ByteBuf base64 = Unpooled.copiedBuffer(m.group(1), CharsetUtil.US_ASCII);
    ByteBuf der = Base64.decode(base64);
    base64.release();
    return der;
  }