Code example for PrivateKey

Methods: getEncodedgetFormat

0
			return null; 
		} 
	} 
 
	protected byte[] getEncoded(PrivateKey key) {
		String format = key.getFormat();
		if (format != null
				&& (format.equalsIgnoreCase("PKCS#8") || format
						.equalsIgnoreCase("PKCS8"))) {
			try { 
				ASN1Primitive keyInfo = BouncyCastleUtil.toASN1Primitive(key
						.getEncoded());
				PrivateKeyInfo pkey = new PrivateKeyInfo((ASN1Sequence) keyInfo);
				ASN1Primitive derKey = pkey.getPrivateKey();
				return BouncyCastleUtil.toByteArray(derKey);
			} catch (IOException e) {
				// that should never happen 
				logger.warn("This shouldn't have happened.", e);
				return new byte[] {}; 
			} 
Experience pair programming with AI  Get Codota for Java