Class PrivateKey
- All Implemented Interfaces:
AutoCloseable
Load, inspect, export, save, and convert one private key.
PrivateKey is a key-container class. It holds one current RSA, DSA, EC, or Ed25519
private key and provides
format conversion, persistence, JWK/XML access, raw EC and Ed25519 access, and public-key
extraction. Cryptographic
operations such as signing, decryption, TLS authentication, and SSH authentication are performed by
other Chilkat
classes that receive the loaded PrivateKey.
Content-based loading
Named load methods inspect the content and recognize supported unencrypted formats. Password-taking loaders also recognize encrypted PKCS #8 and unencrypted input.
Standard export choices
Use PKCS #8 for modern algorithm-independent interchange, encrypted PKCS #8 for password-protected storage, JWK for JOSE, and traditional PEM only when required by a legacy consumer.
One-key state
A successful load replaces the current key. A failed load leaves the object empty. Check
KeyType and BitLength after loading when the expected algorithm matters.
Independent public key
ToPublicKey creates an independent PublicKey that is unaffected when this
object is reloaded with another key.
Key generation
Generate new keys with Rsa, Ecc, or EdDSA, which can place
the generated key into a PrivateKey.
Certificates are separate
A private key does not contain a certificate or chain. Use Cert or Pfx
when certificate association is required.
Recommended format selection: Prefer unencrypted PKCS #8 for transient interchange,
encrypted PKCS #8 with aes256 and a strong password for stored key files, JWK for
JWT/JWS/JWE workflows, and traditional RSA or EC PEM only when the receiving software requires it.
Protect private material: Base64, hexadecimal, PEM, JWK, and XML are encodings or
containers, not encryption. Avoid exporting a private key unless necessary, and protect every
unencrypted representation as sensitive data.
For an extended overview, see PrivateKey Class Overview.
</section>
Event-capable: long-running methods report progress through a ProgressListener installed
with setProgressListener(ProgressListener), onAbortCheck(BooleanSupplier),
onPercentDone(IntPredicate) or onProgressInfo(BiConsumer).
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the nominal size of the loaded private key, in bits.getJwk()Exports the key as a compact JWK (JSON Web Key).getJwkThumbprint(String hashAlg)Computes the RFC 7638 thumbprint of the public portion of the loaded key using the hash algorithm named byhashAlg.Identifies the algorithm of the currently loaded key.getPkcs1ENC(String encoding)Exports the key as the traditional or preferred unencrypted DER representation and encodes the DER as text using the binary encoding named byencoding.Exports the key as unencrypted PEM, preferring the traditional algorithm-specific representation when one exists.getPkcs8ENC(String encoding)Exports the key as unencrypted PKCS #8 DER and encodes the DER as text using the binary encoding named byencoding.Controls the block cipher used by encrypted PKCS #8 export methods.getPkcs8EncryptedENC(String encoding, String password)Exports the key as password-protected PKCS #8 DER, then encodes the encrypted DER as text.getPkcs8EncryptedPem(String password)Exports the key as password-protected PKCS #8 PEM usingpasswordas the password.Exports the key as unencrypted PKCS #8 PEM.voidExports the key as DER and replaces the contents of theBinDatainbd.Returns the installed listener, ornull.getRawHex(StringBuilder pubKey)Exports the raw private value as lowercase hexadecimal and replaces the contents of theStringBuilderinpubKeywith the corresponding raw public key.Provides a catch-all string for specialized compatibility options that are not exposed as ordinary properties.getXml()Exports the key in Chilkat-compatible XML.voidloadAnyFormat(BinData privKeyData, String password)Loads a private key from the data inprivKeyDataby inspecting its contents.voidloadAnyFormatFile(String path, String password)Loads a private key from the file atpathby inspecting its contents.voidloadEd25519(String privKey, String pubKey)Loads an Ed25519 key pair from raw hexadecimal values.voidloadEncryptedPem(String pemStr, String password)Loads a private key from the PEM text inpemStr.voidloadEncryptedPemFile(String path, String password)Loads a private key from the file atpath, usingpasswordwhen the detected key is encrypted.voidLoads a private key from the JWK JSON injsonStr.voidLoads a private key from the PEM text instr.voidloadPemFile(String path)Loads a private key from the file atpath.voidloadPkcs1File(String path)Loads a private key from the file atpath.voidloadPkcs8EncryptedFile(String path, String password)Loads a private key from the file atpath, usingpasswordwhen the detected key is encrypted.voidloadPkcs8File(String path)Loads a private key from the file atpath.voidloadPvkFile(String path, String password)Loads a private key from the file atpath, usingpasswordif the detected representation is encrypted.voidLoads a private key from the XML text inxml.voidloadXmlFile(String path)Loads a private key from the file atpath.voidonAbortCheck(BooleanSupplier callback)Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it.voidonPercentDone(IntPredicate callback)Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it.voidonProgressInfo(BiConsumer<String,String> callback)Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds.voidsavePemFile(String path)Saves the key atpathas unencrypted PEM, preferring a traditional algorithm-specific representation when one exists.voidsavePkcs1File(String path)Saves the key atpathusing the traditional or preferred unencrypted DER representation.Historical method name: RSA is saved as PKCS #1, EC as RFC 5915, DSA in its traditional structure, and Ed25519 as PKCS #8 because no traditional PKCS #1 form exists.File behavior: An existing destination file is replaced.voidsavePkcs8EncryptedFile(String password, String path)Saves the key as password-protected PKCS #8 DER.voidsavePkcs8EncryptedPemFile(String password, String path)Saves the key as password-protected PKCS #8 PEM.voidsavePkcs8File(String path)Saves the key as unencrypted PKCS #8 DER atpath.voidsavePkcs8PemFile(String path)Saves the key as unencrypted PKCS #8 PEM atpath.voidsaveXmlFile(String path)Saves the key as unencrypted Chilkat-compatible XML atpath.voidsetPkcs8EncryptAlg(String value)Sets thePkcs8EncryptAlgproperty; seegetPkcs8EncryptAlg().voidsetProgressListener(ProgressListener listener)Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.voidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().voidtoPublicKey(PublicKey pubKey)Extracts the public portion of the loaded private key and stores an independent copy in thePublicKeysupplied inpubKey.voiduploadToCloud(JsonObject jsonIn, JsonObject jsonOut)Uploads or imports the private key to a supported cloud key-management service.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
PrivateKey
public PrivateKey()Creates a newPrivateKeyobject.
-
-
Method Details
-
getBitLength
public int getBitLength()Returns the nominal size of the loaded private key, in bits. The value is0when the object is empty. For RSA it is the modulus size; for DSA it is the size ofp; for EC it is the named-curve field size; and for Ed25519 it is256.Comparing strength: Bit lengths are meaningful only within the context of the algorithm. A 256-bit EC key and a 256-bit RSA key do not provide comparable security.- Returns:
- the value of the
BitLengthproperty (read-only)
-
getKeyType
Identifies the algorithm of the currently loaded key. The value is one ofempty,rsa,dsa,ecc, ored25519.emptymeans that no usable private key is loaded.One-key state model: APrivateKeyobject holds one current key. Loading another key replaces it; a failed load leaves the object empty.- Returns:
- the value of the
KeyTypeproperty (read-only)
-
getPkcs8EncryptAlg
Controls the block cipher used by encrypted PKCS #8 export methods. Supported values are3des,aes128,aes192, andaes256. Values are case-insensitive and are normalized to lowercase. The default is3des. Assigning an empty or unrecognized value resets the property to3des. All choices use CBC mode.Encrypted PKCS #8 output uses PBES2 with PBKDF2. The generated parameters use an 8-byte salt, 2048 PBKDF2 iterations, and the default PBKDF2 PRF (HMAC-SHA-1). The selected cipher uses CBC mode with a newly generated IV.
Recommended setting: Prefer
aes256for new output unless an older consumer requires 3DES. This property selects encryption parameters only; password quality remains essential.- Returns:
- the value of the
Pkcs8EncryptAlgproperty
-
setPkcs8EncryptAlg
Sets thePkcs8EncryptAlgproperty; seegetPkcs8EncryptAlg().- Parameters:
value- the new value (notnull)
-
getUncommonOptions
Provides a catch-all string for specialized compatibility options that are not exposed as ordinary properties. The default is the empty string, which is appropriate for normal use.Leave empty unless instructed: Set this property only when a Chilkat example, release note, or support response documents a specific option needed for an unusual interoperability case.- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
getJwk
Exports the key as a compact JWK (JSON Web Key). Binary integers and byte strings use Base64url without padding.Key type Members emitted
RSA
kty,n,e,d,p,q,dp,dq,qiEC
kty,crv,x,y,dEd25519
kty=OKP,crv=Ed25519,x,d, anduse=sigKey material only: Optional JOSE metadata loaded from a JWK, such as
kid,alg,key_ops, or a caller-supplieduse, is not retained for re-export. The Ed25519use=sigmember is emitted by Chilkat.Private output: The returned JSON contains private key material and must be protected accordingly.- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getJwkThumbprint
Computes the RFC 7638 thumbprint of the public portion of the loaded key using the hash algorithm named byhashAlg. Supported values includemd5,sha1,sha256,sha384, andsha512. An unsupported name causes the method to fail. The returned digest is Base64url-encoded without padding.Public-key identity: The canonical thumbprint input contains only the required public JWK members. Private members and optional metadata such askid,use, andalgare excluded, so the result matches the thumbprint of the correspondingPublicKey.Recommended hash: Usesha256for normal RFC 7638 interoperability. MD5 and SHA-1 are available for compatibility but should not be chosen for new security-sensitive identifiers.- Parameters:
hashAlg- thehashAlgargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPkcs1ENC
Exports the key as the traditional or preferred unencrypted DER representation and encodes the DER as text using the binary encoding named byencoding. The binary bytes are the same as returned by.Historical method name: PKCS #1 is specifically an RSA standard. For non-RSA key types, this method returns the applicable traditional structure or a PKCS #8 fallback.GetPkcs1Key type Returned representation
RSA
RSAPrivateKeyDER from PKCS #1.DSA The traditional six-integer DSA private-key structure.
EC
ECPrivateKeyDER from RFC 5915.Ed25519 PKCS #8
PrivateKeyInfoDER using the Ed25519 OID1.3.101.112, because Ed25519 has no traditional PKCS #1 form.For RSA, the DER contains:
RSAPrivateKey ::= SEQUENCE { version Version, modulus INTEGER, -- n publicExponent INTEGER, -- e privateExponent INTEGER, -- d prime1 INTEGER, -- p prime2 INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2 INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p otherPrimeInfos OtherPrimeInfos OPTIONAL }For EC, the traditional structure is:
ECPrivateKey ::= SEQUENCE { version INTEGER { ecPrivkeyVer1(1) }, privateKey OCTET STRING, parameters [0] ECParameters OPTIONAL, publicKey [1] BIT STRING OPTIONAL }Encoding validation: An unsupported
encodingencoding name causes the method to fail; it does not silently select another encoding.- Parameters:
encoding- theencodingargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPkcs1Pem
Exports the key as unencrypted PEM, preferring the traditional algorithm-specific representation when one exists.Key type PEM label Body
RSA
RSA PRIVATE KEYPKCS #1 DERDSA
DSA PRIVATE KEYTraditional DSA DEREC
EC PRIVATE KEYRFC 5915 DEREd25519
PRIVATE KEYPKCS #8 DERGenerated PEM formatting: PEM output uses CRLF line endings, Base64 lines of at most 64 characters, and a final CRLF.Security note: The returned private key is not encrypted.
- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPkcs8ENC
Exports the key as unencrypted PKCS #8 DER and encodes the DER as text using the binary encoding named byencoding. PKCS #8 is an algorithm-independent private-key container. Chilkat emits the classic version-0PrivateKeyInfostructure, with the algorithm-specific private-key DER in anOCTET STRING.PrivateKeyInfo ::= SEQUENCE { version Version, privateKeyAlgorithm AlgorithmIdentifier, privateKey OCTET STRING, attributes [0] IMPLICIT Attributes OPTIONAL }Encoding validation: An unsupported
encodingencoding name causes the method to fail; it does not silently select another encoding.Encoding is not encryption: Base64, hexadecimal, and similar encodings only represent the DER bytes as text. They do not protect the private key.- Parameters:
encoding- theencodingargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPkcs8EncryptedENC
Exports the key as password-protected PKCS #8 DER, then encodes the encrypted DER as text.encodingnames the binary encoding andpasswordsupplies the password. The cipher is selected by.getPkcs8EncryptAlg()Encrypted PKCS #8 output uses PBES2 with PBKDF2. The generated parameters use an 8-byte salt, 2048 PBKDF2 iterations, and the default PBKDF2 PRF (HMAC-SHA-1). The selected cipher uses CBC mode with a newly generated IV.
Encoding validation: An unsupported
encodingencoding name causes the method to fail.Empty passwords: A nonempty, strong password should be used. An emptypasswordis accepted but provides no meaningful password protection.- Parameters:
encoding- theencodingargument (notnull)password- thepasswordargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPkcs8EncryptedPem
Exports the key as password-protected PKCS #8 PEM usingpasswordas the password. The cipher is selected by. The output uses:getPkcs8EncryptAlg()-----BEGIN ENCRYPTED PRIVATE KEY----- ... -----END ENCRYPTED PRIVATE KEY-----
Encrypted PKCS #8 output uses PBES2 with PBKDF2. The generated parameters use an 8-byte salt, 2048 PBKDF2 iterations, and the default PBKDF2 PRF (HMAC-SHA-1). The selected cipher uses CBC mode with a newly generated IV.
Generated PEM formatting: PEM output uses CRLF line endings, Base64 lines of at most 64 characters, and a final CRLF.Empty passwords: An empty
passwordis accepted and still produces encrypted PKCS #8, but it provides no meaningful password protection.- Parameters:
password- thepasswordargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPkcs8Pem
Exports the key as unencrypted PKCS #8 PEM. For RSA, EC, and Ed25519, the PEM armor is:-----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY-----
PKCS #8 is an algorithm-independent private-key container. Chilkat emits the classic version-0
PrivateKeyInfostructure, with the algorithm-specific private-key DER in anOCTET STRING.PrivateKeyInfo ::= SEQUENCE { version Version, privateKeyAlgorithm AlgorithmIdentifier, privateKey OCTET STRING, attributes [0] IMPLICIT Attributes OPTIONAL }Generated PEM formatting: PEM output uses CRLF line endings, Base64 lines of at most 64 characters, and a final CRLF.Security note: This output is not password-protected.
- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPkcsBd
Exports the key as DER and replaces the contents of theBinDatainbd.pkcs1passwordOutputtrueIgnored for encryption. RSA PKCS #1, traditional DSA, RFC 5915 EC, or PKCS #8 for Ed25519.falseEmpty string. Unencrypted PKCS #8 DER.falseNonempty password. Encrypted PKCS #8 DER using.getPkcs8EncryptAlg()Output state: A successful call replaces any existing
bdcontent. If the call fails,bdis cleared.Password behavior: Whenpkcs1istrue,passworddoes not encrypt the output. To obtain encrypted output, setpkcs1tofalseand provide a nonemptypassword.- Parameters:
pkcs1- thepkcs1argumentpassword- thepasswordargument (notnull)bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getRawHex
Exports the raw private value as lowercase hexadecimal and replaces the contents of theStringBuilderinpubKeywith the corresponding raw public key.Key type Returned private value Public value in
pubKeyEd25519 The 32-byte seed accepted by
, as 64 hex characters. The 32-byte public key, as 64 hex characters.loadEd25519(String, String)EC The private scalar, padded to the curve size as needed. The uncompressed point
04 || HEX(x) || HEX(y).Applicable key types: This method supports Ed25519 and ordinary EC keys. RSA and DSA keys do not have a single simple raw representation and cause the method to fail.Output on failure: If the method fails,
pubKeyis cleared.- Parameters:
pubKey- thepubKeyargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getXml
Exports the key in Chilkat-compatible XML. The XML is not encrypted. RSA and DSA components use ordinary Base64.RSA keys use:
<RSAKeyValue> <Modulus>...</Modulus> <Exponent>...</Exponent> <D>...</D> <P>...</P> <Q>...</Q> <DP>...</DP> <DQ>...</DQ> <InverseQ>...</InverseQ> </RSAKeyValue>
DSA keys use:
<DSAKeyValue> <P>...</P> <Q>...</Q> <G>...</G> <Y>...</Y> <X>...</X> </DSAKeyValue>
EC keys place the named curve in the
curveattribute and Base64-encode the RFC 5915ECPrivateKeyDER in the element content:<ECCKeyValue curve="secp256r1">...</ECCKeyValue>
Ed25519 keys Base64-encode 64 bytes consisting of the 32-byte private seed followed by the 32-byte public key:
<Ed25519KeyValue>...</Ed25519KeyValue>
Round-trip support: XML produced by this method can be loaded by
,loadXml(String), or the general format-detection methods.Interoperability note: These XML forms are Chilkat-compatible representations. Prefer PKCS #8, PEM, or JWK when interoperating with systems that expect standard key containers.loadXmlFile(String)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadAnyFormat
Loads a private key from the data inprivKeyDataby inspecting its contents. Recognized representations include RSA PKCS #1 DER, traditional DSA and EC DER, PKCS #8 DER, encrypted PKCS #8, PEM, JWK, Chilkat-compatible XML, Microsoft PVK, and supported Ed25519 representations.passwordsupplies the password when the detected representation is encrypted; otherwise it may be empty.Text and binary input:privKeyDatacontains the exact bytes to inspect. Textual PEM, JWK, and XML are detected from those bytes; a filename extension is not involved.Trailing DER data: If the input begins with one complete supported DER key followed by extra bytes or another DER object, the first key is loaded and trailing data is ignored.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
privKeyData- theprivKeyDataargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadAnyFormatFile
Loads a private key from the file atpathby inspecting its contents. Recognized representations include RSA PKCS #1 DER, traditional DSA and EC DER, PKCS #8 DER, encrypted PKCS #8, PEM, JWK, Chilkat-compatible XML, Microsoft PVK, and supported Ed25519 representations.passwordsupplies the password when needed.Filename extensions are advisory: The file content determines the format; a nonstandard or misleading extension does not prevent recognition.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
path- thepathargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadEd25519
Loads an Ed25519 key pair from raw hexadecimal values.privKeyis the 32-byte Ed25519 private seed.pubKeyis the 32-byte public key. Each nonempty value must contain exactly 64 hexadecimal digits. Uppercase hexadecimal and an optional0xprefix are accepted; embedded whitespace is not accepted.pubKeymay be empty, in which case Chilkat derives the public key from the seed.Supplied public key is not verified: WhenpubKeyis nonempty, Chilkat stores the supplied public value without checking that it corresponds toprivKey. Pass an emptypubKeywhen the public key should be derived and guaranteed to match the private seed.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
privKey- theprivKeyargument (notnull)pubKey- thepubKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadEncryptedPem
Loads a private key from the PEM text inpemStr.passwordsupplies the password when the PEM is encrypted. The method accepts encrypted PKCS #8 PEM and also loads supported unencrypted PEM.-----BEGIN ENCRYPTED PRIVATE KEY----- ... -----END ENCRYPTED PRIVATE KEY-----
Content auto-detection: Chilkat examines the content rather than relying on the method name or filename extension. This password-taking method can load both encrypted and unencrypted supported private-key representations.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.Password failure: An incorrect password causes loading to fail and leaves this object empty.
- Parameters:
pemStr- thepemStrargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadEncryptedPemFile
Loads a private key from the file atpath, usingpasswordwhen the detected key is encrypted. The file may contain encrypted PKCS #8 PEM or another supported encrypted or unencrypted representation.Content auto-detection: Chilkat examines the content rather than relying on the method name or filename extension. This password-taking method can load both encrypted and unencrypted supported private-key representations.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
path- thepathargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadJwk
Loads a private key from the JWK JSON injsonStr. Supported private JWK key types are RSA (kty=RSA), EC (kty=EC), and Ed25519 (kty=OKP,crv=Ed25519). An unsupportedktycauses the method to fail.Private key material required: A JWK containing only public members belongs in aPublicKey. This method is for JWKs that contain private key material.Metadata handling: Optional JOSE metadata such askid,use,alg, andkey_opsmay be present but is not retained byPrivateKey.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
jsonStr- thejsonStrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadPem
Loads a private key from the PEM text instr. This method has no password argument and therefore cannot load password-protected PEM. Usefor encrypted input.Content auto-detection: The method name identifies the expected or traditional use, but Chilkat examines the content and can load other supported unencrypted private-key representations. Encrypted input requires a load method that accepts a password.PEM block selection: If the text contains multiple PEM blocks, Chilkat selects the first supported private-key block. It skips preceding public-key or unrelated PEM blocks.Accepted surrounding content: Leading and trailing whitespace, a UTF-8 BOM, and trailing non-PEM text are accepted.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.loadEncryptedPem(String, String)- Parameters:
str- thestrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadPemFile
Loads a private key from the file atpath. This method has no password argument and therefore cannot load a password-protected key. UseorloadEncryptedPemFile(String, String)when a password may be required.Content auto-detection: The method name identifies the expected or traditional use, but Chilkat examines the content and can load other supported unencrypted private-key representations. Encrypted input requires a load method that accepts a password.PEM block selection: For a file containing multiple PEM blocks, Chilkat selects the first supported private-key block and skips preceding public-key or unrelated blocks.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.loadAnyFormatFile(String, String)- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadPkcs1File
Loads a private key from the file atpath. Despite the historical PKCS #1 name, the method examines the content and accepts supported unencrypted private-key representations.Content auto-detection: The method name identifies the expected or traditional use, but Chilkat examines the content and can load other supported unencrypted private-key representations. Encrypted input requires a load method that accepts a password.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadPkcs8EncryptedFile
Loads a private key from the file atpath, usingpasswordwhen the detected key is encrypted. The method can load encrypted PKCS #8 DER or PEM and also supported unencrypted representations.Content auto-detection: Chilkat examines the content rather than relying on the method name or filename extension. This password-taking method can load both encrypted and unencrypted supported private-key representations.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
path- thepathargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadPkcs8File
Loads a private key from the file atpath. Although named for unencrypted PKCS #8, the method examines the file content and accepts other supported unencrypted private-key representations.Content auto-detection: The method name identifies the expected or traditional use, but Chilkat examines the content and can load other supported unencrypted private-key representations. Encrypted input requires a load method that accepts a password.Trailing DER data: When the file begins with a complete supported DER private-key object, trailing bytes or a second concatenated DER object are ignored; the first key is loaded.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadPvkFile
Loads a private key from the file atpath, usingpasswordif the detected representation is encrypted. This Windows-only method supports Microsoft PVK and also participates in Chilkat private-key content auto-detection.Content auto-detection: Chilkat examines the content rather than relying on the method name or filename extension. This password-taking method can load both encrypted and unencrypted supported private-key representations.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
path- thepathargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadXml
Loads a private key from the XML text inxml. Supported Chilkat-compatible XML roots includeRSAKeyValue,DSAKeyValue,ECCKeyValue, andEd25519KeyValue.Content auto-detection: The method name identifies the expected or traditional use, but Chilkat examines the content and can load other supported unencrypted private-key representations. Encrypted input requires a load method that accepts a password.Ed25519 XML: TheEd25519KeyValuecontent is ordinary Base64 for the 32-byte private seed followed by the 32-byte public key.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.- Parameters:
xml- thexmlargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadXmlFile
Loads a private key from the file atpath. Chilkat recognizes RSA, DSA, EC, and Ed25519 XML produced by, and also auto-detects other supported unencrypted private-key representations.Content auto-detection: The method name identifies the expected or traditional use, but Chilkat examines the content and can load other supported unencrypted private-key representations. Encrypted input requires a load method that accepts a password.Object state: A successful load replaces any key already held by this object. If loading fails, this object is left empty.getXml()- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
savePemFile
Saves the key atpathas unencrypted PEM, preferring a traditional algorithm-specific representation when one exists. RSA usesRSA PRIVATE KEY, DSA usesDSA PRIVATE KEY, EC usesEC PRIVATE KEY, and Ed25519 uses the PKCS #8PRIVATE KEYform.Generated PEM formatting: PEM output uses CRLF line endings, Base64 lines of at most 64 characters, and a final CRLF.File behavior: An existing destination file is replaced. Parent directories are not created; the parent directory must already exist.PKCS #8 alternative: Useto always request the algorithm-independent PKCS #8savePkcs8PemFile(String)PRIVATE KEYform.Security note: The file is not password-protected.- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
savePkcs1File
Saves the key atpathusing the traditional or preferred unencrypted DER representation.Historical method name: RSA is saved as PKCS #1, EC as RFC 5915, DSA in its traditional structure, and Ed25519 as PKCS #8 because no traditional PKCS #1 form exists.File behavior: An existing destination file is replaced. Parent directories are not created; the parent directory must already exist.Security note: The file contains cleartext private-key material.- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
savePkcs8EncryptedFile
Saves the key as password-protected PKCS #8 DER.passwordsupplies the password andpathis the destination path. The cipher is selected by.getPkcs8EncryptAlg()Encrypted PKCS #8 output uses PBES2 with PBKDF2. The generated parameters use an 8-byte salt, 2048 PBKDF2 iterations, and the default PBKDF2 PRF (HMAC-SHA-1). The selected cipher uses CBC mode with a newly generated IV.
File behavior: An existing destination file is replaced. Parent directories are not created; the parent directory must already exist.Empty passwords: An empty
passwordis accepted but provides no meaningful password protection.- Parameters:
password- thepasswordargument (notnull)path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
savePkcs8EncryptedPemFile
Saves the key as password-protected PKCS #8 PEM.passwordsupplies the password andpathis the destination path. The file uses theENCRYPTED PRIVATE KEYPEM label, and the cipher is selected by.getPkcs8EncryptAlg()Encrypted PKCS #8 output uses PBES2 with PBKDF2. The generated parameters use an 8-byte salt, 2048 PBKDF2 iterations, and the default PBKDF2 PRF (HMAC-SHA-1). The selected cipher uses CBC mode with a newly generated IV.
Generated PEM formatting: PEM output uses CRLF line endings, Base64 lines of at most 64 characters, and a final CRLF.File behavior: An existing destination file is replaced. Parent directories are not created; the parent directory must already exist.Empty passwords: An empty
passwordis accepted but provides no meaningful password protection.- Parameters:
password- thepasswordargument (notnull)path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
savePkcs8File
Saves the key as unencrypted PKCS #8 DER atpath. PKCS #8 is an algorithm-independent private-key container. Chilkat emits the classic version-0PrivateKeyInfostructure, with the algorithm-specific private-key DER in anOCTET STRING.PrivateKeyInfo ::= SEQUENCE { version Version, privateKeyAlgorithm AlgorithmIdentifier, privateKey OCTET STRING, attributes [0] IMPLICIT Attributes OPTIONAL }File behavior: An existing destination file is replaced. Parent directories are not created; the parent directory must already exist.macOS Keychain: Starting in Chilkat v10.0.0,
pathmay be formatted askeychain:<label>to save the private key to the Apple Keychain.Security note: The file contains cleartext private-key material.- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
savePkcs8PemFile
Saves the key as unencrypted PKCS #8 PEM atpath. The PEM label isPRIVATE KEYfor RSA, EC, Ed25519, and other supported PKCS #8 key types.PKCS #8 is an algorithm-independent private-key container. Chilkat emits the classic version-0PrivateKeyInfostructure, with the algorithm-specific private-key DER in anOCTET STRING.PrivateKeyInfo ::= SEQUENCE { version Version, privateKeyAlgorithm AlgorithmIdentifier, privateKey OCTET STRING, attributes [0] IMPLICIT Attributes OPTIONAL }Generated PEM formatting: PEM output uses CRLF line endings, Base64 lines of at most 64 characters, and a final CRLF.File behavior: An existing destination file is replaced. Parent directories are not created; the parent directory must already exist.Security note: The file is not password-protected.
- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
saveXmlFile
Saves the key as unencrypted Chilkat-compatible XML atpath. The XML representation is the same as returned by.File behavior: An existing destination file is replaced. Parent directories are not created; the parent directory must already exist.Security note: The XML contains cleartext private-key material.getXml()- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
toPublicKey
Extracts the public portion of the loaded private key and stores an independent copy in thePublicKeysupplied inpubKey. The resulting public key is unaffected if thisPrivateKeyis later reloaded with a different key.Target state on failure: If extraction fails, an existing key already held bypubKeyis preserved.- Parameters:
pubKey- thepubKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
uploadToCloud
Uploads or imports the private key to a supported cloud key-management service.jsonInsupplies service-specific input parameters as aJsonObject, andjsonOutreceives service-specific result information.Open-ended interface: The required JSON members and returned JSON depend on the target service and operation. Follow the corresponding Chilkat example for AWS KMS, Azure Key Vault, or another supported provider rather than assuming one common schema.Security note: Cloud import operations may transmit private-key material. Use only the provider endpoint, authentication, and transport settings documented for the intended service.- Parameters:
jsonIn- thejsonInargument (notnull)jsonOut- thejsonOutargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setProgressListener
Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.- Parameters:
listener- the listener, ornull- Throws:
IllegalStateException- if called from inside one of this object's own callbacks
-
getProgressListener
Returns the installed listener, ornull.- Returns:
- the listener installed with
setProgressListener(ProgressListener)or one of theon...methods
-
onAbortCheck
Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onPercentDone
Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onProgressInfo
Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-