io.netty.handler.ssl.SslContext.generateKeySpec()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(166)

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

SslContext.generateKeySpec介绍

[英]Generates a key specification for an (encrypted) private key.
[中]

代码示例

代码示例来源:origin: redisson/redisson

private static PrivateKey getPrivateKeyFromByteBuffer(ByteBuf encodedKeyBuf, String keyPassword)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,
    InvalidAlgorithmParameterException, KeyException, IOException {
  byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()];
  encodedKeyBuf.readBytes(encodedKey).release();
  PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(
      keyPassword == null ? null : keyPassword.toCharArray(), encodedKey);
  try {
    return KeyFactory.getInstance("RSA").generatePrivate(encodedKeySpec);
  } catch (InvalidKeySpecException ignore) {
    try {
      return KeyFactory.getInstance("DSA").generatePrivate(encodedKeySpec);
    } catch (InvalidKeySpecException ignore2) {
      try {
        return KeyFactory.getInstance("EC").generatePrivate(encodedKeySpec);
      } catch (InvalidKeySpecException e) {
        throw new InvalidKeySpecException("Neither RSA, DSA nor EC worked", e);
      }
    }
  }
}

代码示例来源:origin: wildfly/wildfly

private static PrivateKey getPrivateKeyFromByteBuffer(ByteBuf encodedKeyBuf, String keyPassword)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,
    InvalidAlgorithmParameterException, KeyException, IOException {
  byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()];
  encodedKeyBuf.readBytes(encodedKey).release();
  PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(
      keyPassword == null ? null : keyPassword.toCharArray(), encodedKey);
  try {
    return KeyFactory.getInstance("RSA").generatePrivate(encodedKeySpec);
  } catch (InvalidKeySpecException ignore) {
    try {
      return KeyFactory.getInstance("DSA").generatePrivate(encodedKeySpec);
    } catch (InvalidKeySpecException ignore2) {
      try {
        return KeyFactory.getInstance("EC").generatePrivate(encodedKeySpec);
      } catch (InvalidKeySpecException e) {
        throw new InvalidKeySpecException("Neither RSA, DSA nor EC worked", e);
      }
    }
  }
}

代码示例来源:origin: io.netty/netty-handler

private static PrivateKey getPrivateKeyFromByteBuffer(ByteBuf encodedKeyBuf, String keyPassword)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,
    InvalidAlgorithmParameterException, KeyException, IOException {
  byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()];
  encodedKeyBuf.readBytes(encodedKey).release();
  PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(
      keyPassword == null ? null : keyPassword.toCharArray(), encodedKey);
  try {
    return KeyFactory.getInstance("RSA").generatePrivate(encodedKeySpec);
  } catch (InvalidKeySpecException ignore) {
    try {
      return KeyFactory.getInstance("DSA").generatePrivate(encodedKeySpec);
    } catch (InvalidKeySpecException ignore2) {
      try {
        return KeyFactory.getInstance("EC").generatePrivate(encodedKeySpec);
      } catch (InvalidKeySpecException e) {
        throw new InvalidKeySpecException("Neither RSA, DSA nor EC worked", e);
      }
    }
  }
}

代码示例来源:origin: apache/activemq-artemis

private static PrivateKey getPrivateKeyFromByteBuffer(ByteBuf encodedKeyBuf, String keyPassword)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,
    InvalidAlgorithmParameterException, KeyException, IOException {
  byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()];
  encodedKeyBuf.readBytes(encodedKey).release();
  PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(
      keyPassword == null ? null : keyPassword.toCharArray(), encodedKey);
  try {
    return KeyFactory.getInstance("RSA").generatePrivate(encodedKeySpec);
  } catch (InvalidKeySpecException ignore) {
    try {
      return KeyFactory.getInstance("DSA").generatePrivate(encodedKeySpec);
    } catch (InvalidKeySpecException ignore2) {
      try {
        return KeyFactory.getInstance("EC").generatePrivate(encodedKeySpec);
      } catch (InvalidKeySpecException e) {
        throw new InvalidKeySpecException("Neither RSA, DSA nor EC worked", e);
      }
    }
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

private static PrivateKey getPrivateKeyFromByteBuffer(ByteBuf encodedKeyBuf, String keyPassword)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,
    InvalidAlgorithmParameterException, KeyException, IOException {
  byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()];
  encodedKeyBuf.readBytes(encodedKey).release();
  PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(
      keyPassword == null ? null : keyPassword.toCharArray(), encodedKey);
  try {
    return KeyFactory.getInstance("RSA").generatePrivate(encodedKeySpec);
  } catch (InvalidKeySpecException ignore) {
    try {
      return KeyFactory.getInstance("DSA").generatePrivate(encodedKeySpec);
    } catch (InvalidKeySpecException ignore2) {
      try {
        return KeyFactory.getInstance("EC").generatePrivate(encodedKeySpec);
      } catch (InvalidKeySpecException e) {
        throw new InvalidKeySpecException("Neither RSA, DSA nor EC worked", e);
      }
    }
  }
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

private static PrivateKey getPrivateKeyFromByteBuffer(ByteBuf encodedKeyBuf, String keyPassword)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,
    InvalidAlgorithmParameterException, KeyException, IOException {
  byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()];
  encodedKeyBuf.readBytes(encodedKey).release();
  PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(
      keyPassword == null ? null : keyPassword.toCharArray(), encodedKey);
  try {
    return KeyFactory.getInstance("RSA").generatePrivate(encodedKeySpec);
  } catch (InvalidKeySpecException ignore) {
    try {
      return KeyFactory.getInstance("DSA").generatePrivate(encodedKeySpec);
    } catch (InvalidKeySpecException ignore2) {
      try {
        return KeyFactory.getInstance("EC").generatePrivate(encodedKeySpec);
      } catch (InvalidKeySpecException e) {
        throw new InvalidKeySpecException("Neither RSA, DSA nor EC worked", e);
      }
    }
  }
}

相关文章