OpenPGP Module
Properties Methods Events Config Settings Errors
The OpenPGP module is used to encrypt/decrypt and sign/verify PGP messages.
Syntax
IPWorksEncrypt.Openpgp
Remarks
The OpenPGP class supports encrypting/decrypting and signing/verifying OpenPGP messages in the format specified by RFC 4880.
The Encrypt, Sign, and SignAndEncrypt methods are used to create a message to be sent to your partner. You can additionally create messages bound for multiple recipients with different keys, simultaneously encrypt and compress with the most popular compression algorithms, and control other aspects such as the encrypting algorithm to use.
When a message is received, the Decrypt, VerifySignature, and DecryptAndVerifySignature methods are used to process the incoming message.
The Key* properties specify the key (with private key) used to sign and decrypt.
The SignerKey* properties specify the key used to verify a signature.
The RecipientKey* properties specify the key used to encrypt.
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
When a valid source is found the search stops. The order in which the output properties are checked is as follows:
- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.
Property List
The following is the full list of the properties of the module with short descriptions. Click on the links for further details.
ASCIIArmor | Specifies whether to use ASCII armor to encode the output message. |
AutoSelectAlgorithms | Whether to automatically select algorithms when encrypting or signing. |
ClearSignature | Specifies whether or not to create a cleartext signature. |
CompressionMethod | The compression algorithm used. |
DetachedSignature | Specifies whether or not to generate a detached signature when signing a message. |
EncryptingAlgorithm | The encryption algorithm used when encrypting. |
InputFile | The file to process. |
InputMessage | The message to process. |
Keys | A collection of keys used for cryptographic operations. |
MessageHeaders | A collection of headers in the ASCII armored message. |
OutputFile | The output file. |
OutputMessage | The output message after processing. |
Overwrite | Indicates whether or not the module should overwrite files. |
RecipientKeys | The collection of keys belonging to the recipient of the message. |
SignerKeys | The collection of keys belonging to the signer of the message. |
SigningAlgorithm | The signature hash algorithm used when signing. |
Method List
The following is the full list of the methods of the module with short descriptions. Click on the links for further details.
Config | Sets or retrieves a configuration setting. |
Decrypt | Decrypts the message. |
DecryptAndVerifySignature | Decrypts and verifies the signature of the message. |
Encrypt | Encrypts the message. |
GetRecipientInfo | Gets recipient information for an encrypted message. |
Reset | Resets the module properties. |
Sign | Signs the message. |
SignAndEncrypt | Signs and encrypts the current message. |
VerifySignature | Verifies the signature of the current message. |
Event List
The following is the full list of the events fired by the module with short descriptions. Click on the links for further details.
Error | Fired when information is available about errors during data delivery. |
KeyPassphrase | Fired if the passphrase of current key is incorrect or empty. |
Progress | Fired as progress is made. |
RecipientInfo | Fired for each recipient key of the encrypted message. |
SignatureInfo | Fired during verification of the signed message. |
Status | Shows the progress of the operation. |
VerificationStatus | Fired after verification of the signed message. |
Config Settings
The following is a list of config settings for the module with short descriptions. Click on the links for further details.
AllowEmptyInput | Whether to allow empty files for input. |
AllowOldPacketType | Whether to allow the older encrypted packet type. |
CloseInputStreamAfterProcessing | Determines whether or not the input stream is closed after processing. |
CloseOutputStreamAfterProcessing | Determines whether or not the output stream is closed after processing. |
CompressionLevel | The level of compression used. |
DeleteOutputFileOnError | Whether to delete the output file on an error. |
DetachedSignatureData | The detached signature. |
EnsureValidDSASignatureHashAlgorithm | Whether or not to select a suitable signature hash algorithm automatically. |
FileName | The original name of the encrypted file. |
KeyIdLength | The length of the KeyId available. |
KeySelectionMethod | The method used to select a key for encryption or signing. |
LogLevel | Specifies the level of detail that is logged. |
PGPZipDir | The directory used when creating or extracting a PGP zip file. |
ProgressEventThreshold | The amount of data in bytes to process before firing the progress event. |
PublicKeyringFile | The file name of the public keyring file. |
ReadFromProgressEvent | Whether to read input data from inside the progress event. |
RecursiveDecryptMode | Whether the encrypted data should be decrypted recursively. |
RequireEncryption | Whether to throw an error when decrypting and encryption is not detected. |
RequireIntegrityProtectedPacket | Whether an MDC packet is required for decryption. |
RequireSignature | Whether to throw an error when verifying a signature and no signature is found. |
RequireValidSignature | Specifies if an invalid signature is considered an error condition. |
SecretKeyringFile | The file name of the secret keyring file. |
SplitHeaders | Controls whether ASCII Armor headers are split or not. |
SymmetricPassphrase | The password used for symmetric encryption or decryption. |
UseFipsCompliantAlgorithms | Restricts the usage to FIPS compliant algorithms only. |
VersionHeader | The Version header value in the ASCII armored OpenPGP message. |
WriteToProgressEvent | Whether to write output data so it is accessible from inside the progress event. |
BuildInfo | Information about the product's build. |
CodePage | The system code page used for Unicode to Multibyte translations. |
LicenseInfo | Information about the current license. |
MaskSensitive | Whether sensitive data is masked in log messages. |
UseInternalSecurityAPI | Whether or not to use the system security libraries or an internal implementation. |
ASCIIArmor Property (OpenPGP Module)
Specifies whether to use ASCII armor to encode the output message.
Syntax
public var asciiArmor: Bool { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=ASCIIArmor,setter=setASCIIArmor:) BOOL ASCIIArmor; - (BOOL)ASCIIArmor; - (void)setASCIIArmor :(BOOL)newASCIIArmor;
Default Value
False
Remarks
This property controls whether or not ASCII armoring is used on the output message. The default value is False.
AutoSelectAlgorithms Property (OpenPGP Module)
Whether to automatically select algorithms when encrypting or signing.
Syntax
public var autoSelectAlgorithms: Int32 { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=autoSelectAlgorithms,setter=setAutoSelectAlgorithms:) int autoSelectAlgorithms; - (int)autoSelectAlgorithms; - (void)setAutoSelectAlgorithms :(int)newAutoSelectAlgorithms;
Default Value
0
Remarks
This property is set to the binary 'OR' of one or more options indicating which algorithms to automatically select.
When enabled automatic selection is performed by examining the perferred algorithms specified by the key.
When Encrypt is called the class will read the preferred encryption algorithm and compression method from the key specified in the RecipientKey* properties.
If multiple keys are specified the preferred encryption algorithm and compression method from the last key is used. The EncryptingAlgorithm and CompressionMethod properties are ignored.
When Sign is called the class will read the preferred MAC algorithm and compression method from the private key specified in the Key* properties. If multiple keys are specified the preferred MAC algorithm and compression method from the last key is used. The SigningAlgorithm and CompressionMethod properties are ignored.
The list below defines available options.
Compression Algorithm | 1 (Hex 0x01) |
Cipher Algorithm | 2 (Hex 0x02) |
MAC Algorithm | 4 (Hex 0x04) |
The default value is 0 which means algorithms are not automatically selected.
ClearSignature Property (OpenPGP Module)
Specifies whether or not to create a cleartext signature.
Syntax
public var clearSignature: Bool { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=clearSignature,setter=setClearSignature:) BOOL clearSignature; - (BOOL)clearSignature; - (void)setClearSignature :(BOOL)newClearSignature;
Default Value
False
Remarks
This property controls whether or not a cleartext signature is created during signing. The default value is False. When set to true a clear text signature will be created when Sign is called.
CompressionMethod Property (OpenPGP Module)
The compression algorithm used.
Syntax
public var compressionMethod: String { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=compressionMethod,setter=setCompressionMethod:) NSString* compressionMethod; - (NSString*)compressionMethod; - (void)setCompressionMethod :(NSString*)newCompressionMethod;
Default Value
"zip"
Remarks
This property specifies which compression method is used when generating output. Possible values are:
- zip (default)
- zlib
- bzip2
- none or uncompressed
DetachedSignature Property (OpenPGP Module)
Specifies whether or not to generate a detached signature when signing a message.
Syntax
public var detachedSignature: Bool { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=detachedSignature,setter=setDetachedSignature:) BOOL detachedSignature; - (BOOL)detachedSignature; - (void)setDetachedSignature :(BOOL)newDetachedSignature;
Default Value
False
Remarks
This property specifies whether or not a detached signature is created when signing a message. The default value is False.
If set to true the output will only be the signature. The data being signed will not be included in the output. If set to true ClearSignature will be ignored.
When this property is false (default) the signature is not detached. The output will contain both the signed data and the signature.
EncryptingAlgorithm Property (OpenPGP Module)
The encryption algorithm used when encrypting.
Syntax
public var encryptingAlgorithm: String { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=encryptingAlgorithm,setter=setEncryptingAlgorithm:) NSString* encryptingAlgorithm; - (NSString*)encryptingAlgorithm; - (void)setEncryptingAlgorithm :(NSString*)newEncryptingAlgorithm;
Default Value
"AES128"
Remarks
This property specifies the encryption algorithm used when encrypting. Possible values are:
- CAST5
- 3DES or TripleDES
- AES256
- AES192
- AES128 (default)
- BLOWFISH
- TWOFISH
- IDEA
InputFile Property (OpenPGP Module)
The file to process.
Syntax
public var inputFile: String { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=inputFile,setter=setInputFile:) NSString* inputFile; - (NSString*)inputFile; - (void)setInputFile :(NSString*)newInputFile;
Default Value
""
Remarks
This property specifies the file to be processed. Set this property to the full or relative path to the file which will be processed.
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
- InputFile
- InputMessage
When a valid source is found the search stops. The order in which the output properties are checked is as follows:
- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.
InputMessage Property (OpenPGP Module)
The message to process.
Syntax
public var inputMessage: String { get {...} set {...} }
public var inputMessageB: Data { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=inputMessage,setter=setInputMessage:) NSString* inputMessage; - (NSString*)inputMessage; - (void)setInputMessage :(NSString*)newInputMessage; @property (nonatomic,readwrite,assign,getter=inputMessageB,setter=setInputMessageB:) NSData* inputMessageB; - (NSData*)inputMessageB; - (void)setInputMessageB :(NSData*)newInputMessage;
Default Value
""
Remarks
This property specifies the message to be processed. Set this property to the OpenPGP message content.
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
- InputFile
- InputMessage
When a valid source is found the search stops. The order in which the output properties are checked is as follows:
- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.
Keys Property (OpenPGP Module)
A collection of keys used for cryptographic operations.
Syntax
public var keys: Array<Key> { get {...} }
@property (nonatomic,readwrite,assign,getter=keyCount,setter=setKeyCount:) int keyCount; - (int)keyCount; - (void)setKeyCount :(int)newKeyCount; - (NSString*)keyEncoded:(int)keyIndex; - (void)setKeyEncoded:(int)keyIndex :(NSString*)newKeyEncoded; - (NSData*)keyEncodedB:(int)keyIndex; - (void)setKeyEncodedB:(int)keyIndex :(NSData*)newKeyEncoded; - (NSString*)keyKeyring:(int)keyIndex; - (void)setKeyKeyring:(int)keyIndex :(NSString*)newKeyKeyring; - (NSString*)keyPassphrase:(int)keyIndex; - (void)setKeyPassphrase:(int)keyIndex :(NSString*)newKeyPassphrase; - (NSString*)keyUserId:(int)keyIndex; - (void)setKeyUserId:(int)keyIndex :(NSString*)newKeyUserId;
Default Value
"SHA256"
Remarks
This collection holds keys that are used for signing and decrypting. In most cases only one key will be specified, however multiple keys may be needed in some cases.
MessageHeaders Property (OpenPGP Module)
A collection of headers in the ASCII armored message.
Syntax
public var messageHeaders: Array<Header> { get {...} }
@property (nonatomic,readwrite,assign,getter=messageHeaderCount,setter=setMessageHeaderCount:) int messageHeaderCount; - (int)messageHeaderCount; - (void)setMessageHeaderCount :(int)newMessageHeaderCount; - (NSString*)messageHeaderField:(int)messageHeaderIndex; - (void)setMessageHeaderField:(int)messageHeaderIndex :(NSString*)newMessageHeaderField; - (NSString*)messageHeaderValue:(int)messageHeaderIndex; - (void)setMessageHeaderValue:(int)messageHeaderIndex :(NSString*)newMessageHeaderValue;
Default Value
"SHA256"
Remarks
This property holds a collection of headers specified in the message. It is only applicable when ASCIIArmor is set to true.
When generating ASCII armored output the class will include the headers specified here in addition to the standard Version header.
After decrypting or verifying a message that is ASCII armored this collection will be populated with the headers that were present in the message.
OutputFile Property (OpenPGP Module)
The output file.
Syntax
public var outputFile: String { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=outputFile,setter=setOutputFile:) NSString* outputFile; - (NSString*)outputFile; - (void)setOutputFile :(NSString*)newOutputFile;
Default Value
""
Remarks
This property specifies the file to which the output will be written. This may be set to an absolute or relative path.
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
When a valid source is found the search stops. The order in which the output properties are checked is as follows:
- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.
OutputMessage Property (OpenPGP Module)
The output message after processing.
Syntax
public var outputMessage: String { get {...} set {...} }
public var outputMessageB: Data { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=outputMessage,setter=setOutputMessage:) NSString* outputMessage; - (NSString*)outputMessage; - (void)setOutputMessage :(NSString*)newOutputMessage; @property (nonatomic,readwrite,assign,getter=outputMessageB,setter=setOutputMessageB:) NSData* outputMessageB; - (NSData*)outputMessageB; - (void)setOutputMessageB :(NSData*)newOutputMessage;
Default Value
""
Remarks
This property will be populated with the output from the operation if OutputFile is not set.
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
When a valid source is found the search stops. The order in which the output properties are checked is as follows:
- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.
Overwrite Property (OpenPGP Module)
Indicates whether or not the module should overwrite files.
Syntax
public var overwrite: Bool { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=overwrite,setter=setOverwrite:) BOOL overwrite; - (BOOL)overwrite; - (void)setOverwrite :(BOOL)newOverwrite;
Default Value
False
Remarks
This property indicates whether or not the class will overwrite OutputFile. If Overwrite is False, an error will be thrown whenever OutputFile exists before an operation. The default value is False.
RecipientKeys Property (OpenPGP Module)
The collection of keys belonging to the recipient of the message.
Syntax
public var recipientKeys: Array<Key> { get {...} }
@property (nonatomic,readwrite,assign,getter=recipientKeyCount,setter=setRecipientKeyCount:) int recipientKeyCount; - (int)recipientKeyCount; - (void)setRecipientKeyCount :(int)newRecipientKeyCount; - (NSString*)recipientKeyEncoded:(int)recipientKeyIndex; - (void)setRecipientKeyEncoded:(int)recipientKeyIndex :(NSString*)newRecipientKeyEncoded; - (NSData*)recipientKeyEncodedB:(int)recipientKeyIndex; - (void)setRecipientKeyEncodedB:(int)recipientKeyIndex :(NSData*)newRecipientKeyEncoded; - (NSString*)recipientKeyKeyring:(int)recipientKeyIndex; - (void)setRecipientKeyKeyring:(int)recipientKeyIndex :(NSString*)newRecipientKeyKeyring; - (NSString*)recipientKeyUserId:(int)recipientKeyIndex; - (void)setRecipientKeyUserId:(int)recipientKeyIndex :(NSString*)newRecipientKeyUserId;
Default Value
"SHA256"
Remarks
This property contains the keys of the message recipient.
Set this property before calling Encrypt or SignAndEncrypt.
SignerKeys Property (OpenPGP Module)
The collection of keys belonging to the signer of the message.
Syntax
public var signerKeys: Array<Key> { get {...} }
@property (nonatomic,readwrite,assign,getter=signerKeyCount,setter=setSignerKeyCount:) int signerKeyCount; - (int)signerKeyCount; - (void)setSignerKeyCount :(int)newSignerKeyCount; - (NSString*)signerKeyEncoded:(int)signerKeyIndex; - (void)setSignerKeyEncoded:(int)signerKeyIndex :(NSString*)newSignerKeyEncoded; - (NSData*)signerKeyEncodedB:(int)signerKeyIndex; - (void)setSignerKeyEncodedB:(int)signerKeyIndex :(NSData*)newSignerKeyEncoded; - (NSString*)signerKeyKeyring:(int)signerKeyIndex; - (void)setSignerKeyKeyring:(int)signerKeyIndex :(NSString*)newSignerKeyKeyring; - (NSString*)signerKeyUserId:(int)signerKeyIndex; - (void)setSignerKeyUserId:(int)signerKeyIndex :(NSString*)newSignerKeyUserId;
Default Value
"SHA256"
Remarks
This property contains the keys of the message signer.
Set this property before calling VerifySignature or DecryptAndVerifySignature.
SigningAlgorithm Property (OpenPGP Module)
The signature hash algorithm used when signing.
Syntax
public var signingAlgorithm: String { get {...} set {...} }
@property (nonatomic,readwrite,assign,getter=signingAlgorithm,setter=setSigningAlgorithm:) NSString* signingAlgorithm; - (NSString*)signingAlgorithm; - (void)setSigningAlgorithm :(NSString*)newSigningAlgorithm;
Default Value
"SHA256"
Remarks
This property specifies the signature hash algorithm used when signing. Possible values are:
- SHA1
- MD5
- SHA256 (default)
- SHA384
- SHA512
- SHA224
- RIPEMD160
Config Method (OpenPGP Module)
Sets or retrieves a configuration setting.
Syntax
- (NSString*)config:(NSString*)configurationString;
Remarks
Config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
Decrypt Method (OpenPGP Module)
Decrypts the message.
Syntax
public func decrypt() throws -> Void
- (void)decrypt;
Remarks
This method decrypts the specified message.
The message will be decrypted using the keys specified in the Key* properties. Before decryption begins the class will fire the RecipientInfo event with information about the encrypted message, including the key used to encrypt the message. Within this event you may use the available information to load the correct key into Keys.
DecryptAndVerifySignature Method (OpenPGP Module)
Decrypts and verifies the signature of the message.
Syntax
public func decryptAndVerifySignature() throws -> Void
- (void)decryptAndVerifySignature;
Remarks
This method attempts to both decrypt and verify the signature of the message. All of the properties affected by calling the Decrypt and VerifySignature methods are affected in the same manner.
This method may be used when the data is signed, encrypted, or signed and encrypted. For instance, if the data is encrypted but not signed you may still use this method and the class will perform the decryption without error.
The message will be decrypted using the keys specified in the Key* properties. Before decryption begins the class will fire the RecipientInfo event with information about the encrypted message, including the key used to encrypt the message. Within this event you may use the available information to load the correct key into Keys.
The message will be verified using the keys specified in the SignerKey* properties. Before verification begins the class will fire the SignatureInfo event with information about the signature including the key used to sign the message. Within this event you may use the information available to load the correct key into the SignerKey* properties.
By default, if the signature is not valid the class . The configuration setting RequireValidSignature may be set to False to disable this requirement. When RequireValidSignature is set to False, the Status parameter of the VerificationStatus event should be checked to determine the result of the operation.
NOTE: This method does not attempt to check the validity of the signing key itself.
Encrypt Method (OpenPGP Module)
Encrypts the message.
Syntax
public func encrypt() throws -> Void
- (void)encrypt;
Remarks
This method encrypts the specified message.
The message is encrypted with the public keys specified in the RecipientKey* properties.
When encrypting, the following properties may be used to further configure the class:
GetRecipientInfo Method (OpenPGP Module)
Gets recipient information for an encrypted message.
Syntax
public func getRecipientInfo() throws -> Void
- (void)getRecipientInfo;
Remarks
This method will fire a RecipientInfo event for every recipient key for which the message has been encrypted. The event will provide the KeyId, which can be used to identify the correct key to be used for decryption.
Reset Method (OpenPGP Module)
Resets the component properties.
Syntax
public func reset() throws -> Void
- (void)reset;
Remarks
This method resets all message and key properties to their default values.
Sign Method (OpenPGP Module)
Signs the message.
Syntax
public func sign() throws -> Void
- (void)sign;
Remarks
This method signs the specified message.
The message is signed with the private key specified in the Key* properties.
When signing, the following properties may be used to further configure the class:
SignAndEncrypt Method (OpenPGP Module)
Signs and encrypts the current message.
Syntax
public func signAndEncrypt() throws -> Void
- (void)signAndEncrypt;
Remarks
This method signs and encrypts the specified message.
The message is encrypted with the public keys specified in the RecipientKey* properties and signed with the private key specified in the Key* properties .
When encrypting, the following properties may be used to further configure the class:
When signing, the following properties may be used to further configure the class:
VerifySignature Method (OpenPGP Module)
Verifies the signature of the current message.
Syntax
public func verifySignature() throws -> Void
- (void)verifySignature;
Remarks
This method verifies the signature of the message.
The message will be verified using the keys specified in the SignerKey* properties. Before verification begins the class will fire the SignatureInfo event with information about the signature including the key used to sign the message. Within this event you may use the information available to load the correct key into the SignerKey* properties.
By default, if the signature is not valid the class . The configuration setting RequireValidSignature may be set to False to disable this requirement. When RequireValidSignature is set to False, the Status parameter of the VerificationStatus event should be checked to determine the result of the operation.
Error Event (OpenPGP Module)
Fired when information is available about errors during data delivery.
Syntax
- (void)onError:(int)errorCode :(NSString*)description;
Remarks
The Error event is fired in case of exceptional conditions during message processing. Normally the class .
The ErrorCode parameter contains an error code, and the Description parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.
KeyPassphrase Event (OpenPGP Module)
Fired if the passphrase of current key is incorrect or empty.
Syntax
func onKeyPassphrase(userId: String, keyId: String, passphrase: inout String)
- (void)onKeyPassphrase:(NSString*)userId :(NSString*)keyId :(NSString**)passphrase;
Remarks
This event fires when the passphrase for the key is required. The passphrase must be specified before operations requiring the secret key are attempted. The passphrase may be supplied by setting the Passphrase parameter in this event, or by specifying the KeysPassphrase property before attempting the operation.
The passphrase is required when using the following methods in KeyMgr:
- AddUserId
- SignUserId
- ChangeExpirationDate
- ChangePassphrase
When using the OpenPGP class, or an email-based class, the following methods require a passphrase for the key:
Progress Event (OpenPGP Module)
Fired as progress is made.
Syntax
func onProgress(bytesProcessed: Int64, percentProcessed: Int32, operation: Int32, isEOF: inout Bool)
- (void)onProgress:(long long)bytesProcessed :(int)percentProcessed :(int)operation :(int*)isEOF;
Remarks
This event is fired automatically as data is processed by the class.
The PercentProcessed parameter indicates the current status of the operation.
The BytesProcessed parameter holds the total number of bytes processed so far.
The Operation parameter is only applicable when either ReadFromProgressEvent or WriteToProgressEvent is set to True. This parameter defines whether a Read or Write operation is required. If the configuration settings are not set this parameter will always return 0. Possible values are:
0 | None |
1 | Read |
2 | Write |
The IsEOF parameter is only applicable when either ReadFromProgressEvent or WriteToProgressEvent is set to True. This parameter defines whether the Read or Write operation is complete. When the Operation is Read (1) this parameter must be set to indicate that all data has been supplied to the class. When the Operation is Write (2) this value may be queried to determine when all data has been processed.
RecipientInfo Event (OpenPGP Module)
Fired for each recipient key of the encrypted message.
Syntax
- (void)onRecipientInfo:(NSString*)keyId :(NSString*)publicKeyAlgorithm;
Remarks
This event fires when the Decrypt or DecryptAndVerifySignature method is called.
KeyId is the Id of the key used to encrypt the message. If a subkey was used to encrypt the message this will be the Id of that subkey. It is the hex-encoded, 4- or 8-byte Id of the key. It is the same as the last 4 or 8 bytes of the fingerprint. For instance:
BF52A0ABThis can be used to identify the correct key to specify in Keys. Keys can be set from within this event as this event fires directly before the decryption process begins.
SignatureInfo Event (OpenPGP Module)
Fired during verification of the signed message.
Syntax
- (void)onSignatureInfo:(NSString*)keyId :(NSString*)signingAlgorithm :(NSString*)publicKeyAlgorithm;
Remarks
This event fires when the VerifySignature or DecryptAndVerifySignature method is called. It provides information about the signature of the message.
KeyId is the Id of the key used to sign the message. If a subkey was used to sign the message this will be the Id of that subkey. It is the hex-encoded, 4- or 8-byte Id of the key. It is the same as the last 4 or 8 bytes of the Fingerprint. For instance:
BF52A0ABThis can be used to identify the correct key to specify in the SignerKey* properties. This property can be set from within this event as this event fires directly before the verification process begins.
SigningAlgorithm describes the hash algorithm used when the message was originally signed. This value is applicable only to the message signature, not the key used to sign the message. Possible values are:
- SHA1
- SHA256
- SHA384
- SHA512
- SHA224
- MD5
PublicKeyAlgorithm is the algorithm of the public key used to sign the message. Possible values are:
- RSA
- DSA
- ECDSA
- EdDSA
Status Event (OpenPGP Module)
Shows the progress of the operation.
Syntax
func onStatus(message: String)
- (void)onStatus:(NSString*)message;
Remarks
The event is fired for informational and logging purposes only. It may be used to track the progress of an operation.
The level of detail is controlled by the LogLevel setting.
VerificationStatus Event (OpenPGP Module)
Fired after verification of the signed message.
Syntax
- (void)onVerificationStatus:(NSString*)keyId :(int)status;
Remarks
This event fires when VerifySignature or DecryptAndVerifySignature is called. It provides information about the result.
KeyId is the Id of the key used to sign the message. It is the hex-encoded, 4-or 8-byte Id of the key. It is the same as the last 4 or 8 bytes of the Fingerprint. For instance:
BF52A0AB
Status holds the result of the operation. Possible values are:
0 | Verification succeeded |
1 | Verification failed |
2 | The required key could not be found |
3 | Verification succeeded but the key is expired. |
Header Type
This is an HTTP header as it is received from the server.
Remarks
When a header is received through a Header event, it is parsed into a Header type. This type contains a , and its corresponding .
Fields
field
String
Default Value: ""
This property contains the name of the HTTP Header (this is the same case as it is delivered).
value
String
Default Value: ""
This property contains the Header contents.
Constructors
public init()
public init(field: , value: )
Key Type
The OpenPGP key being used.
Remarks
This type describes the current key. The key may be a public or secret key. The fields are used to identify or select the key.
Fields
curve
String (read-only)
Default Value: ""
This property specifies the elliptic curve used in the ECDSA or EdDSA key. This property is only applicable if is ECDSA or EdDSA. Possible values are:
Value | PublicKeyAlgorithm | Description |
secp256r1 | ECDSA | NIST curve P-256 |
secp384r1 | ECDSA | NIST curve P-384 |
secp521r1 | ECDSA | NIST curve P-521 |
Ed25519 | EdDSA | Ed25519 |
secp256k1 | EdDSA | Secp256k1 |
effectiveDate
String (read-only)
Default Value: ""
The date when this key becomes valid. Prior to this it is not valid. The following is an example of a valid encoded date:
23-Jan-2000 15:00:00.
encodedB
Data
Default Value: ""
The key. This property is used to assign a specific key. The properties may also be used to specify a key.
encoded
String
Default Value: ""
The key. This property is used to assign a specific key. The properties may also be used to specify a key.
expirationDate
String (read-only)
Default Value: ""
The date the key expires. After this date the key will no longer be valid. The following is an example of a valid encoded date:
23-Jan-2001 15:00:00.
fingerprint
String (read-only)
Default Value: ""
The hex-encoded, 20-byte fingerprint of the key.
This is in the form:
5E70662EA810E768391A2FE8F7B7D49C89C9D7B1
id
String (read-only)
Default Value: ""
The hex-encoded, 4-byte key Id. It is same as last 4 bytes of .
This is in the form:
89C9D7B1The KeyIdLength setting may be set to a value of 8 to return the last 8 bytes instead of the last 4 bytes.
keyring
String
Default Value: ""
The location of the keyring.
If the keyring is stored in a directory, set this property to the directory. The directory must contain the files "secring.gpg" and "pubring.gpg". A keyring may also be stored in a single file. If the keyring is a file this property should be set to the path of the file.
When This property is set the class will read the keyring and populate the Key* properties with the first key found in the keyring. Set KeyUserId to select a different key in the current keyring.
otherUserIds
String (read-only)
Default Value: ""
If the specified key has alternate user Ids associated with it, this property returns a comma-separated list of the other user Ids.
passphrase
String
Default Value: ""
The passphrase for the key's secret key (if any). This must be specified before operations requiring the secret key are attempted. The passphrase may be supplied in this property or through the KeyPassphrase event, which will fire when a passphrase is required.
The passphrase is required when using the following methods in KeyMgr:
- AddUserId
- SignUserId
- ChangeExpirationDate
- ChangePassphrase
When using the OpenPGP class, or an email-based class, the following methods require a passphrase for the key:
- Decrypt
- Sign
- SignAndEncrypt
publicKey
String (read-only)
Default Value: ""
The public key of the key. The key is provided as ASCII armored data.
publicKeyAlgorithm
String (read-only)
Default Value: ""
A text description of the public key algorithm of the key. Possible values are:
- RSA
- DSA
- ECDSA
- EdDSA
- RSA-Legacy
publicKeyLength
Int32 (read-only)
Default Value: 0
The length of the public key in bits. Common values are 512, 1024, and 2048.
If the property is ECDSA or EcDSA the length of the public key is determined by the . Possible lenghts are:
Curve | Public Key Length (bits) |
secp256r1 | 256 |
secp384r1 | 384 |
secp521r1 | 521 |
Ed25519 | 256 |
secp256k1 | 256 |
revoked
Bool (read-only)
Default Value: False
Whether or not the key is revoked.
secretKey
String (read-only)
Default Value: ""
The secret key of the key (if available). The key is provided as ASCII armored data.
secretKeyAvailable
Bool (read-only)
Default Value: False
Whether or not a secret key is available for the selected key.
usage
String (read-only)
Default Value: ""
The value will be of one or more of the following strings, separated by commas:
- Certifying Other Certificates
- Signing Emails and Files
- Encrypting Emails and Files
- Split Key
- Authenticate Against Servers
- Group Key
usageFlags
Int32 (read-only)
Default Value: 47
Flags that show the intended use for the key. The default value is 0x0F. The value of is a combination of the following flags:
0x01 | This key may be used to certify other keys. |
0x02 | This key may be used to sign data. |
0x0C | This key may be used to encrypt communications and encrypt storage. |
0x10 | The private component of this key may have been split by a secret-sharing mechanism. |
0x20 | This key may be used for authentication. |
0x80 | The private component of this key may be in the possession of more than one person. |
userId
String
Default Value: ""
The user Id of the key. When a key is loaded this property is populated with the user Id associated with the key. This property may be set to load a key from the Keyring. When this property is set the class will search the Keyring for a key associated with the UserId specified.
When loading a key with multiple user Ids, this property will be populated with the UserId that was most recently added to the key. To discover all of the UserIds associated with a key query this property and KeyOtherUserIds after loading the key.
The UserId format is:
FirstName LastName (Comment) <Email>Not all values are required when selecting or generating a key, but at least FirstName or Email are required.
When using this property to select a key you may also specify the key's Id, or any of its subkeys' Ids, instead of a user Id. The class will then search for a key with a matching Id. This is helpful in situations where you do not have the UserId but still need to load the key, such as within the OpenPGP class's RecipientInfo event.
Constructors
public init(keyPath: )
Reads the OpenPGP public key from the specified KeyPath . If multiple keys are present only the first one is used.
public init(keyData: )
Reads the OpenPGP key from the specified KeyData . Both binary-formatted and ASCII-armored data are accepted.
public init(keyPath: , userId: )
Searches the KeyPath for an OpenPGP key with a matching UserId . If UserId is set to "*" the first key will be used.
public init(keyData: , userId: )
Searches the KeyData for an OpenPGP key with a matching UserId . If UserId is set to "*" the first key will be used.
Config Settings (OpenPGP Module)
The class accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.OpenPGP Config Settings
When set to True the class will read the features from the recipient key to determine if the older packet type is required. If the key does require the old packet type, then the older packet type will be used. If the key does not require the old packet type, then the new integrity protected packet type will still be used.
By default this value is False. This means under no conditions is the older less secure packet type used. The newer integrity protected packet type is always used.
Only enable this setting if you have a requirement to do so.
zlib | 1-6 |
zip | 1-6 |
bzip2 | 1-9 |
89011C04000102000605025100459B000A0910E2...
DSA Notes
DSA requires that the hash be 160 bits or larger, which means MD5 is not a suitable algorithm. When DSA Signature Hash Algorithm selection is enabled (default) the class will use the preferred algorithm from the key if it meets the requirements for DSA. If the preferred algorithm is MD5 and does not meed the requirements for DSA the class will automatically use a suitable algorithm based on the Q element of the DSA key (may be SHA1, SHA224, or SHA256).
ECDSA Notes
The ECDSA Signature Hash Algorithm requirements are directly related to the KeyCurve used by the key. When this setting is enabled (default) the class will use the preferred algorithm from the key if it meets the requirements for ECDSA. If the preferred algorithm does not meet the requirements the class will automatically select a valid hash algorithm based on the curve as follows:
Curve | Hash Algorithm |
secp256r1 | SHA256 |
secp384r1 | SHA384 |
secp521r1 | SHA512 |
secp256k1 | SHA256 |
0 | Automatic selection, first suitable subkey. Expired keys accepted. |
1 | Automatic selection, first suitable subkey. Expired keys not accepted. |
2 | Automatic selection, newest suitable subkey. Expired keys not accepted (Default). |
99 | Manual Selection. |
Manual Selection
To manually select a key for any operation pass the key's Id in the constructor.
Openpgp pgp = new Openpgp();
pgp.Config("KeySelectionMethod=99");
pgp.RecipientKeys.Add(new Key(@"C:\path\to\key.asc", "7CA1376C39768977")); // Key with Id 7CA1376C39768977 will be used for encryption.
0 (None) | No events are logged. |
1 (Info - default) | Informational events are logged. |
2 (Verbose) | Detailed data is logged. |
3 (Debug) | Debug data is logged. |
- To create a PGP zip file set this value to a location on disk including a filemask and call Encrypt. For instance:
OpenPGP1.Config("PGPZipDir=C:\MyFiles\*.txt"); OpenPGP1.OutputFile = "C:\PGPZip.pgp"; OpenPGP1.Encrypt();
The created file returned in the OutputFile property is the PGP zip. If InputFile is specified it is used to temporarily hold the Tar archive while creating the PGP zip file. The temporary file is not automatically deleted. If InputFile is not specified the Tar archive is held in memory while creating the PGP zip file. - To extract a PGP zip file set this value to a location on disk and call Decrypt. For instance:
OpenPGP1.Config("PGPZipDir=C:\MyFiles"); OpenPGP1.InputFile = "C:\PGPZip.pgp"; OpenPGP1.Decrypt();
The extracted files will be present in the specified directory. If OutputFile is specified it is used to temporarily hold the Tar archive. The temporary file is not automatically deleted. If OutputFile is not specified the Tar archive is held in memory while extracting the PGP zip file. Note that if the OpenPGP message supplied is not a PGP zip file the decryption will occur as normal without error.
0 | Automatic - If the PGP message contains the special header version "PGP Command Line" then recursive decryption will be attempted. (Default) |
1 | Always attempt recursive decryption. |
2 | Never attempt recursive decryption. |
The default value is false.
The default value is false.
- 3DES
- AES128
- AES192
- AES256
- RSA
- DSA
- SHA1
- SHA256
- SHA384
- SHA512
- SHA224
This setting will be populated after calling Decrypt, VerifySignature, or DecryptAndVerifySignature.
Base Config Settings
The following is a list of valid code page identifiers:
Identifier | Name |
037 | IBM EBCDIC - U.S./Canada |
437 | OEM - United States |
500 | IBM EBCDIC - International |
708 | Arabic - ASMO 708 |
709 | Arabic - ASMO 449+, BCON V4 |
710 | Arabic - Transparent Arabic |
720 | Arabic - Transparent ASMO |
737 | OEM - Greek (formerly 437G) |
775 | OEM - Baltic |
850 | OEM - Multilingual Latin I |
852 | OEM - Latin II |
855 | OEM - Cyrillic (primarily Russian) |
857 | OEM - Turkish |
858 | OEM - Multilingual Latin I + Euro symbol |
860 | OEM - Portuguese |
861 | OEM - Icelandic |
862 | OEM - Hebrew |
863 | OEM - Canadian-French |
864 | OEM - Arabic |
865 | OEM - Nordic |
866 | OEM - Russian |
869 | OEM - Modern Greek |
870 | IBM EBCDIC - Multilingual/ROECE (Latin-2) |
874 | ANSI/OEM - Thai (same as 28605, ISO 8859-15) |
875 | IBM EBCDIC - Modern Greek |
932 | ANSI/OEM - Japanese, Shift-JIS |
936 | ANSI/OEM - Simplified Chinese (PRC, Singapore) |
949 | ANSI/OEM - Korean (Unified Hangul Code) |
950 | ANSI/OEM - Traditional Chinese (Taiwan; Hong Kong SAR, PRC) |
1026 | IBM EBCDIC - Turkish (Latin-5) |
1047 | IBM EBCDIC - Latin 1/Open System |
1140 | IBM EBCDIC - U.S./Canada (037 + Euro symbol) |
1141 | IBM EBCDIC - Germany (20273 + Euro symbol) |
1142 | IBM EBCDIC - Denmark/Norway (20277 + Euro symbol) |
1143 | IBM EBCDIC - Finland/Sweden (20278 + Euro symbol) |
1144 | IBM EBCDIC - Italy (20280 + Euro symbol) |
1145 | IBM EBCDIC - Latin America/Spain (20284 + Euro symbol) |
1146 | IBM EBCDIC - United Kingdom (20285 + Euro symbol) |
1147 | IBM EBCDIC - France (20297 + Euro symbol) |
1148 | IBM EBCDIC - International (500 + Euro symbol) |
1149 | IBM EBCDIC - Icelandic (20871 + Euro symbol) |
1200 | Unicode UCS-2 Little-Endian (BMP of ISO 10646) |
1201 | Unicode UCS-2 Big-Endian |
1250 | ANSI - Central European |
1251 | ANSI - Cyrillic |
1252 | ANSI - Latin I |
1253 | ANSI - Greek |
1254 | ANSI - Turkish |
1255 | ANSI - Hebrew |
1256 | ANSI - Arabic |
1257 | ANSI - Baltic |
1258 | ANSI/OEM - Vietnamese |
1361 | Korean (Johab) |
10000 | MAC - Roman |
10001 | MAC - Japanese |
10002 | MAC - Traditional Chinese (Big5) |
10003 | MAC - Korean |
10004 | MAC - Arabic |
10005 | MAC - Hebrew |
10006 | MAC - Greek I |
10007 | MAC - Cyrillic |
10008 | MAC - Simplified Chinese (GB 2312) |
10010 | MAC - Romania |
10017 | MAC - Ukraine |
10021 | MAC - Thai |
10029 | MAC - Latin II |
10079 | MAC - Icelandic |
10081 | MAC - Turkish |
10082 | MAC - Croatia |
12000 | Unicode UCS-4 Little-Endian |
12001 | Unicode UCS-4 Big-Endian |
20000 | CNS - Taiwan |
20001 | TCA - Taiwan |
20002 | Eten - Taiwan |
20003 | IBM5550 - Taiwan |
20004 | TeleText - Taiwan |
20005 | Wang - Taiwan |
20105 | IA5 IRV International Alphabet No. 5 (7-bit) |
20106 | IA5 German (7-bit) |
20107 | IA5 Swedish (7-bit) |
20108 | IA5 Norwegian (7-bit) |
20127 | US-ASCII (7-bit) |
20261 | T.61 |
20269 | ISO 6937 Non-Spacing Accent |
20273 | IBM EBCDIC - Germany |
20277 | IBM EBCDIC - Denmark/Norway |
20278 | IBM EBCDIC - Finland/Sweden |
20280 | IBM EBCDIC - Italy |
20284 | IBM EBCDIC - Latin America/Spain |
20285 | IBM EBCDIC - United Kingdom |
20290 | IBM EBCDIC - Japanese Katakana Extended |
20297 | IBM EBCDIC - France |
20420 | IBM EBCDIC - Arabic |
20423 | IBM EBCDIC - Greek |
20424 | IBM EBCDIC - Hebrew |
20833 | IBM EBCDIC - Korean Extended |
20838 | IBM EBCDIC - Thai |
20866 | Russian - KOI8-R |
20871 | IBM EBCDIC - Icelandic |
20880 | IBM EBCDIC - Cyrillic (Russian) |
20905 | IBM EBCDIC - Turkish |
20924 | IBM EBCDIC - Latin-1/Open System (1047 + Euro symbol) |
20932 | JIS X 0208-1990 & 0121-1990 |
20936 | Simplified Chinese (GB2312) |
21025 | IBM EBCDIC - Cyrillic (Serbian, Bulgarian) |
21027 | Extended Alpha Lowercase |
21866 | Ukrainian (KOI8-U) |
28591 | ISO 8859-1 Latin I |
28592 | ISO 8859-2 Central Europe |
28593 | ISO 8859-3 Latin 3 |
28594 | ISO 8859-4 Baltic |
28595 | ISO 8859-5 Cyrillic |
28596 | ISO 8859-6 Arabic |
28597 | ISO 8859-7 Greek |
28598 | ISO 8859-8 Hebrew |
28599 | ISO 8859-9 Latin 5 |
28605 | ISO 8859-15 Latin 9 |
29001 | Europa 3 |
38598 | ISO 8859-8 Hebrew |
50220 | ISO 2022 Japanese with no halfwidth Katakana |
50221 | ISO 2022 Japanese with halfwidth Katakana |
50222 | ISO 2022 Japanese JIS X 0201-1989 |
50225 | ISO 2022 Korean |
50227 | ISO 2022 Simplified Chinese |
50229 | ISO 2022 Traditional Chinese |
50930 | Japanese (Katakana) Extended |
50931 | US/Canada and Japanese |
50933 | Korean Extended and Korean |
50935 | Simplified Chinese Extended and Simplified Chinese |
50936 | Simplified Chinese |
50937 | US/Canada and Traditional Chinese |
50939 | Japanese (Latin) Extended and Japanese |
51932 | EUC - Japanese |
51936 | EUC - Simplified Chinese |
51949 | EUC - Korean |
51950 | EUC - Traditional Chinese |
52936 | HZ-GB2312 Simplified Chinese |
54936 | Windows XP: GB18030 Simplified Chinese (4 Byte) |
57002 | ISCII Devanagari |
57003 | ISCII Bengali |
57004 | ISCII Tamil |
57005 | ISCII Telugu |
57006 | ISCII Assamese |
57007 | ISCII Oriya |
57008 | ISCII Kannada |
57009 | ISCII Malayalam |
57010 | ISCII Gujarati |
57011 | ISCII Punjabi |
65000 | Unicode UTF-7 |
65001 | Unicode UTF-8 |
Identifier | Name |
1 | ASCII |
2 | NEXTSTEP |
3 | JapaneseEUC |
4 | UTF8 |
5 | ISOLatin1 |
6 | Symbol |
7 | NonLossyASCII |
8 | ShiftJIS |
9 | ISOLatin2 |
10 | Unicode |
11 | WindowsCP1251 |
12 | WindowsCP1252 |
13 | WindowsCP1253 |
14 | WindowsCP1254 |
15 | WindowsCP1250 |
21 | ISO2022JP |
30 | MacOSRoman |
10 | UTF16String |
0x90000100 | UTF16BigEndian |
0x94000100 | UTF16LittleEndian |
0x8c000100 | UTF32String |
0x98000100 | UTF32BigEndian |
0x9c000100 | UTF32LittleEndian |
65536 | Proprietary |
- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
- Last Valid Build: The last valid build number for which the license will work.
This setting only works on these classes: AS3Receiver, AS3Sender, Atom, Client(3DS), FTP, FTPServer, IMAP, OFTPClient, SSHClient, SCP, Server(3DS), Sexec, SFTP, SFTPServer, SSHServer, TCPClient, TCPServer.
Setting this configuration setting to tells the class to use the internal implementation instead of using the system security libraries.
This setting is set to by default on all platforms.
Trappable Errors (OpenPGP Module)
OpenPGP Errors
101 Cannot decode ASCII Armor data. | |
102 Unknown ASCII Armor data type. | |
103 Checksum failed. | |
104 Unknown ASCII Armor header. | |
105 Cannot decode PGP packet. | |
106 Cannot encode PGP packet. | |
107 Unknown PGP packet tag. | |
108 Unsupported version. | |
109 Unsupported algorithm. | |
110 Unknown subpacket. | |
111 Internal error. | |
112 Feature not supported. | |
113 Secret data was not encrypted. | |
114 Cannot find the key. | |
115 Error reading file. | |
116 Error writing file. | |
117 Error reading key. | |
118 Error writing key. | |
119 Cannot verify signature. | |
120 Cannot create signature. | |
121 Invalid UserId. | |
122 Invalid passphrase. | |
123 Data encryption failed. | |
124 Error creating key. | |
125 Unsupported symmetric algorithm. | |
126 Unsupported hash. | |
127 Unsupported compression algorithm. | |
128 Invalid key usage. | |
129 Component is busy. | |
130 Error decrypting data. | |
131 Data is not compressed. | |
132 Error decompressing data. | |
133 Error compressing data. | |
134 Unsupported signature. | |
135 Failed to overwrite file. | |
141 No input. | |
142 Signing was required, but the message was not signed. | |
143 Encryption was required, but the message was not encrypted. | |
146 No data integrity packet was found (MDC), but one was required. | |
200 Out of memory. |