PemPrivateKey Class — netty Architecture
Architecture documentation for the PemPrivateKey class in PemPrivateKey.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd["PemPrivateKey"] 4cdc865a_2ef1_546e_7172_89fa2ddf3b07["PemPrivateKey.java"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|defined in| 4cdc865a_2ef1_546e_7172_89fa2ddf3b07 e02cbddc_61f5_edfc_e533_8fa5cd528f66["PemEncoded()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| e02cbddc_61f5_edfc_e533_8fa5cd528f66 65a84c25_7c7d_0557_e4a7_5d8e560efb81["PemPrivateKey()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| 65a84c25_7c7d_0557_e4a7_5d8e560efb81 145b2308_8882_17de_9621_bd68e80b21d0["isSensitive()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| 145b2308_8882_17de_9621_bd68e80b21d0 55c46237_c1ae_d1cb_cb4e_d970a5f0acb0["ByteBuf()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| 55c46237_c1ae_d1cb_cb4e_d970a5f0acb0 e444c62b_746e_b67e_e288_e347a67db7bf["deallocate()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| e444c62b_746e_b67e_e288_e347a67db7bf 2b412e17_958b_c6dd_234e_f17ff9e428c3["getEncoded()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| 2b412e17_958b_c6dd_234e_f17ff9e428c3 ee91f25a_0991_c7f3_3df6_9408d830d1d6["String()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| ee91f25a_0991_c7f3_3df6_9408d830d1d6 27438891_8e8f_f9e3_6fb5_8804b735981a["destroy()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| 27438891_8e8f_f9e3_6fb5_8804b735981a f5cd26ec_ff8c_3640_98af_86d6fcf13de2["isDestroyed()"] 194af198_e026_5c8c_6eb7_d6fe9fc1c1fd -->|method| f5cd26ec_ff8c_3640_98af_86d6fcf13de2
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/PemPrivateKey.java lines 43–230
public final class PemPrivateKey extends AbstractReferenceCounted implements PrivateKey, PemEncoded {
private static final long serialVersionUID = 7978017465645018936L;
private static final byte[] BEGIN_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----\n".getBytes(CharsetUtil.US_ASCII);
private static final byte[] END_PRIVATE_KEY = "\n-----END PRIVATE KEY-----\n".getBytes(CharsetUtil.US_ASCII);
private static final String PKCS8_FORMAT = "PKCS#8";
/**
* Creates a {@link PemEncoded} value from the {@link PrivateKey}.
*/
static PemEncoded toPEM(ByteBufAllocator allocator, boolean useDirect, PrivateKey key) {
// We can take a shortcut if the private key happens to be already
// PEM/PKCS#8 encoded. This is the ideal case and reason why all
// this exists. It allows the user to pass pre-encoded bytes straight
// into OpenSSL without having to do any of the extra work.
if (key instanceof PemEncoded) {
return ((PemEncoded) key).retain();
}
byte[] bytes = key.getEncoded();
if (bytes == null) {
throw new IllegalArgumentException(key.getClass().getName() + " does not support encoding");
}
return toPEM(allocator, useDirect, bytes);
}
static PemEncoded toPEM(ByteBufAllocator allocator, boolean useDirect, byte[] bytes) {
ByteBuf encoded = Unpooled.wrappedBuffer(bytes);
try {
ByteBuf base64 = SslUtils.toBase64(allocator, encoded);
try {
int size = BEGIN_PRIVATE_KEY.length + base64.readableBytes() + END_PRIVATE_KEY.length;
boolean success = false;
final ByteBuf pem = useDirect ? allocator.directBuffer(size) : allocator.buffer(size);
try {
pem.writeBytes(BEGIN_PRIVATE_KEY);
pem.writeBytes(base64);
pem.writeBytes(END_PRIVATE_KEY);
PemValue value = new PemValue(pem, true);
success = true;
return value;
} finally {
// Make sure we never leak that PEM ByteBuf if there's an Exception.
if (!success) {
SslUtils.zerooutAndRelease(pem);
}
}
} finally {
SslUtils.zerooutAndRelease(base64);
}
} finally {
SslUtils.zerooutAndRelease(encoded);
}
}
/**
* Creates a {@link PemPrivateKey} from raw {@code byte[]}.
*
* ATTENTION: It's assumed that the given argument is a PEM/PKCS#8 encoded value.
* No input validation is performed to validate it.
*/
public static PemPrivateKey valueOf(byte[] key) {
return valueOf(Unpooled.wrappedBuffer(key));
}
/**
* Creates a {@link PemPrivateKey} from raw {@code ByteBuf}.
*
* ATTENTION: It's assumed that the given argument is a PEM/PKCS#8 encoded value.
* No input validation is performed to validate it.
*/
public static PemPrivateKey valueOf(ByteBuf key) {
return new PemPrivateKey(key);
}
private final ByteBuf content;
Source
Frequently Asked Questions
What is the PemPrivateKey class?
PemPrivateKey is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/PemPrivateKey.java.
Where is PemPrivateKey defined?
PemPrivateKey is defined in handler/src/main/java/io/netty/handler/ssl/PemPrivateKey.java at line 43.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free