CryptorRSA
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
public class CryptorRSA
RSA Encryption/Decryption, Signing/Verification
-
Create a plaintext data container.
Declaration
Swift
public class func createPlaintext(with data: Data) -> PlaintextData
Parameters
data
Data
containing the key data.Return Value
Newly initialized
PlaintextData
. -
Creates a message from a plaintext string, with the specified encoding.
Declaration
Swift
public class func createPlaintext(with string: String, using encoding: String.Encoding) throws -> PlaintextData
Parameters
string
String value of the plaintext message
encoding
Encoding to use to generate the clear data
Return Value
Newly initialized
PlaintextData
. -
Create an encrypted data container.
Declaration
Swift
public class func createEncrypted(with data: Data) -> EncryptedData
Parameters
data
Data
containing the encrypted data.Return Value
Newly initialized
EncryptedData
. -
Creates a message with a encrypted base64-encoded string.
Declaration
Swift
public class func createEncrypted(with base64String: String) throws -> EncryptedData
Parameters
base64String
Base64-encoded data of an encrypted message
Return Value
Newly initialized
EncryptedData
. -
Create an signed data container.
Declaration
Swift
public class func createSigned(with data: Data) -> SignedData
Parameters
data
Data
containing the signed data.Return Value
Newly initialized
SignedData
. -
RSA Data Object: Allows for RSA Encryption/Decryption, Signing/Verification and various utility functions.
See moreDeclaration
Swift
public class RSAData
-
Plaintext Data - Represents data not encrypted or signed.
Declaration
Swift
public class PlaintextData : RSAData
-
X509 Certificate Extension
Declaration
Swift
static let CER_SUFFIX: String
-
PEM Suffix
Declaration
Swift
static let PEM_SUFFIX: String
-
DER Suffix
Declaration
Swift
static let DER_SUFFIX: String
-
PEM Begin Marker
Declaration
Swift
static let PEM_BEGIN_MARKER: String
-
PEM End Marker
Declaration
Swift
static let PEM_END_MARKER: String
-
PK Begin Marker
Declaration
Swift
static let PK_BEGIN_MARKER: String
-
PK End Marker
Declaration
Swift
static let PK_END_MARKER: String
-
SK Begin Marker
Declaration
Swift
static let SK_BEGIN_MARKER: String
-
SK End Marker
Declaration
Swift
static let SK_END_MARKER: String
-
Generic Begin Marker
Declaration
Swift
static let GENERIC_BEGIN_MARKER: String
-
Generic End Marker
Declaration
Swift
static let GENERIC_END_MARKER: String
-
Undocumented
Declaration
Swift
public static let ERR_DOMAIN: String
-
Undocumented
Declaration
Swift
public static let ERR_ADD_KEY: Int
-
Undocumented
Declaration
Swift
public static let ERR_DELETE_KEY: Int
-
Undocumented
Declaration
Swift
public static let ERR_STRIP_PK_HEADER: Int
-
Undocumented
Declaration
Swift
public static let ERR_INIT_PK: Int
-
Undocumented
Declaration
Swift
public static let ERR_BASE64_PEM_DATA: Int
-
Undocumented
Declaration
Swift
public static let ERR_STRING_ENCODING: Int
-
Undocumented
Declaration
Swift
public static let ERR_KEY_NOT_PUBLIC: Int
-
Undocumented
Declaration
Swift
public static let ERR_KEY_NOT_PRIVATE: Int
-
Undocumented
Declaration
Swift
public static let ERR_NOT_ENCRYPTED: Int
-
Undocumented
Declaration
Swift
public static let ERR_ENCRYPTION_FAILED: Int
-
Undocumented
Declaration
Swift
public static let ERR_NOT_SIGNED_DATA: Int
-
Undocumented
Declaration
Swift
public static let ERR_NOT_PLAINTEXT: Int
-
Undocumented
Declaration
Swift
public static let ERR_DECRYPTION_FAILED: Int
-
Undocumented
Declaration
Swift
public static let ERR_SIGNING_FAILED: Int
-
Undocumented
Declaration
Swift
public static let ERR_VERIFICATION_FAILED: Int
-
Undocumented
Declaration
Swift
public static let ERR_CREATE_CERT_FAILED: Int
-
Undocumented
Declaration
Swift
public static let ERR_EXTRACT_PUBLIC_KEY_FAILED: Int
-
Undocumented
Declaration
Swift
public static let ERR_EXTRACT_PRIVATE_KEY_FAILED: Int
-
Undocumented
Declaration
Swift
public static let ERR_NOT_IMPLEMENTED: Int
-
See moreRSA
specific error structure.Declaration
Swift
public struct Error : Swift.Error, CustomStringConvertible
-
Creates a public key by extracting it from a certificate.
Declaration
Swift
public class func createPublicKey(extractingFrom certName: String, onPath path: String) throws -> PublicKey
Parameters
certName
Name of the certificate file.
path
Path where the file is located.
Return Value
New
PublicKey
instance. -
Creates a key with a PEM file.
Declaration
Swift
public class func createPublicKey(withPEMNamed pemName: String, in bundle: Bundle = Bundle.main) throws -> PublicKey
Parameters
pemName
Name of the PEM file
bundle
Bundle in which to look for the PEM file. Defaults to the main bundle.
Return Value
New
PublicKey
instance. -
Creates a key with a DER file.
Declaration
Swift
public class func createPublicKey(withDERNamed derName: String, in bundle: Bundle = Bundle.main) throws -> PublicKey
Parameters
derName
Name of the DER file
bundle
Bundle in which to look for the DER file. Defaults to the main bundle.
Return Value
New
PublicKey
instance. -
Creates a public key by extracting it from a certificate.
Declaration
Swift
public class func createPublicKey(extractingFrom certName: String, in bundle: Bundle = Bundle.main) throws -> PublicKey
Parameters
certName
Name of the certificate file.
bundle
Bundle in which to look for the DER file. Defaults to the main bundle.
Return Value
New
PublicKey
instance.
-
Creates a private key with data.
Declaration
Swift
public class func createPrivateKey(with data: Data) throws -> PrivateKey
Parameters
data
Key data
Return Value
New
PrivateKey
instance. -
Creates a key with a base64-encoded string.
Declaration
Swift
public class func createPrivateKey(withBase64 base64String: String) throws -> PrivateKey
Parameters
base64String
Base64-encoded key data
Return Value
New
PrivateKey
instance. -
Creates a key with a PEM string.
Declaration
Swift
public class func createPrivateKey(withPEM pemString: String) throws -> PrivateKey
Parameters
pemString
PEM-encoded key string
Return Value
New
PrivateKey
instance. -
Creates a key with a PEM file.
Declaration
Swift
public class func createPrivateKey(withPEMNamed pemName: String, onPath path: String) throws -> PrivateKey
Parameters
pemName
Name of the PEM file
path
Path where the file is located.
Return Value
New
PrivateKey
instance. -
Creates a key with a DER file.
Declaration
Swift
public class func createPrivateKey(withDERNamed derName: String, onPath path: String) throws -> PrivateKey
Parameters
derName
Name of the DER file
path
Path where the file is located.
Return Value
New
PrivateKey
instance. -
Creates a key with a PEM file.
Declaration
Swift
public class func createPrivateKey(withPEMNamed pemName: String, in bundle: Bundle = Bundle.main) throws -> PrivateKey
Parameters
pemName
Name of the PEM file
bundle
Bundle in which to look for the PEM file. Defaults to the main bundle.
Return Value
New
PrivateKey
instance. -
Creates a key with a DER file.
Declaration
Swift
public class func createPrivateKey(withDERNamed derName: String, in bundle: Bundle = Bundle.main) throws -> PrivateKey
Parameters
derName
Name of the DER file
bundle
Bundle in which to look for the DER file. Defaults to the main bundle.
Return Value
New
PrivateKey
instance. -
Create a new RSA public/private key pair.
Declaration
Swift
public class func makeKeyPair(_ keySize: RSAKey.KeySize) throws -> (PrivateKey, PublicKey)
Parameters
keySize
The size of the generated RSA keys in bits.
Return Value
A tuple containing the (
PrivateKey
,PublicKey
) instances.
-
RSA Key Creation and Handling
See moreDeclaration
Swift
public class RSAKey
-
Create a key from key data.
-
Retrieve the OpenSSL error and text.
-
Convert DER data to PEM data.
Declaration
Swift
static func convertDerToPem(from derData: Data, type: CryptorRSA.RSAKey.KeyType) -> String
Parameters
derData
Data
in DER format.type
Type of key data.
Return Value
PEM
Data
representation. -
Get the Base64 representation of a PEM encoded string after stripping off the PEM markers.
Declaration
Swift
static func base64String(for pemString: String) throws -> String
Parameters
pemString
String
containing PEM formatted data.Return Value
Base64 encoded
String
containing the data. -
This function strips the x509 from a provided ASN.1 DER public key. If the key doesn’t contain a header, the DER data is returned as is.
Declaration
Swift
static func stripX509CertificateHeader(for keyData: Data) throws -> Data
Parameters
keyData
Data
containing the public key with or without the x509 header.Return Value
Data
containing the public with header (if present) removed. -
Add an X509 certificate header to key data.
Declaration
Swift
static func addX509CertificateHeader(for keyData: Data) -> Data
Parameters
keyData
Data to add the header to.
Return Value
The modified key data.