/** * Create a PrivateKeyInfo representation of a private key. * * @param privateKey the key to be encoded into the info object. * @return the appropriate PrivateKeyInfo * @throws java.io.IOException on an error encoding the key */ public static PrivateKeyInfo createPrivateKeyInfo(AsymmetricKeyParameter privateKey) throws IOException { return createPrivateKeyInfo(privateKey, null); }
extractBytes(encKey, size, 0, priv.getD());
@Override public byte[] getEncoded() { try { return PrivateKeyInfoFactory.createPrivateKeyInfo(this.parameters).getEncoded(); } catch (IOException e) { return null; } } }
@Override public byte[] getEncoded() { try { return PrivateKeyInfoFactory.createPrivateKeyInfo(parameters).getEncoded(); } catch (IOException e) { return null; } } }
@Override public PrivateKey toKey(PrivateKeyParameters key) { try { // Optimization if (key instanceof BcAsymmetricKeyParameters) { String keyType = checkKeyType((BcAsymmetricKeyParameters) key); if (keyType != null) { throw new IllegalArgumentException(String.format(CLASS_ERROR, keyType, PRIVATE, key.getClass().getName())); } return generatePrivate(PrivateKeyInfoFactory.createPrivateKeyInfo( ((BcAsymmetricKeyParameters) key).getParameters())); } // Fallback return generatePrivate(PrivateKeyInfo.getInstance(key.getEncoded())); } catch (IOException e) { throw new IllegalArgumentException("Invalid private key parameters: " + key.getClass().getName()); } }
@Override public PrivateKey toKey(PrivateKeyParameters key) { try { // Optimization if (key instanceof BcAsymmetricKeyParameters) { String keyType = checkKeyType((BcAsymmetricKeyParameters) key); if (keyType != null) { throw new IllegalArgumentException(String.format(CLASS_ERROR, keyType, PRIVATE, key.getClass().getName())); } return generatePrivate( PrivateKeyInfoFactory.createPrivateKeyInfo( ((BcAsymmetricKeyParameters) key).getParameters())); } // Fallback return generatePrivate(PrivateKeyInfo.getInstance(key.getEncoded())); } catch (IOException e) { throw new IllegalArgumentException("Invalid private key parameters: " + key.getClass().getName()); } }
/** * @return Encoded PrivateKeyInfo structure in the case of a private key, otherwise an encoded SubjectPublicKeyInfo * structure. */ @Override public byte[] getEncoded() { try { if (delegate.isPrivate()) { return PrivateKeyInfoFactory.createPrivateKeyInfo(delegate).getEncoded(); } return SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(delegate).getEncoded(); } catch (IOException e) { throw new EncodingException("Key encoding error", e); } } }
public byte[] getEncoded() { try { ASN1Set attrSet = ASN1Set.getInstance(attributes); PrivateKeyInfo privInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(xdhPrivateKey, attrSet); if (hasPublicKey) { return privInfo.getEncoded(); } else { return new PrivateKeyInfo(privInfo.getPrivateKeyAlgorithm(), privInfo.parsePrivateKey(), attrSet).getEncoded(); } } catch (IOException e) { return null; } }
public byte[] getEncoded() { try { ASN1Set attrSet = ASN1Set.getInstance(attributes); PrivateKeyInfo privInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(eddsaPrivateKey, attrSet); if (hasPublicKey) { return privInfo.getEncoded(); } else { return new PrivateKeyInfo(privInfo.getPrivateKeyAlgorithm(), privInfo.parsePrivateKey(), attrSet).getEncoded(); } } catch (IOException e) { return null; } }
PrivateKeyInfo pInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(params); PrivateKeyInfo pInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(params);