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) -> PlaintextDataParameters
dataDatacontaining 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 -> PlaintextDataParameters
stringString value of the plaintext message
encodingEncoding 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) -> EncryptedDataParameters
dataDatacontaining 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 -> EncryptedDataParameters
base64StringBase64-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) -> SignedDataParameters
dataDatacontaining 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 moreRSAspecific 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 -> PublicKeyParameters
certNameName of the certificate file.
pathPath where the file is located.
Return Value
New
PublicKeyinstance. -
Creates a key with a PEM file.
Declaration
Swift
public class func createPublicKey(withPEMNamed pemName: String, in bundle: Bundle = Bundle.main) throws -> PublicKeyParameters
pemNameName of the PEM file
bundleBundle in which to look for the PEM file. Defaults to the main bundle.
Return Value
New
PublicKeyinstance. -
Creates a key with a DER file.
Declaration
Swift
public class func createPublicKey(withDERNamed derName: String, in bundle: Bundle = Bundle.main) throws -> PublicKeyParameters
derNameName of the DER file
bundleBundle in which to look for the DER file. Defaults to the main bundle.
Return Value
New
PublicKeyinstance. -
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 -> PublicKeyParameters
certNameName of the certificate file.
bundleBundle in which to look for the DER file. Defaults to the main bundle.
Return Value
New
PublicKeyinstance.
-
Creates a private key with data.
Declaration
Swift
public class func createPrivateKey(with data: Data) throws -> PrivateKeyParameters
dataKey data
Return Value
New
PrivateKeyinstance. -
Creates a key with a base64-encoded string.
Declaration
Swift
public class func createPrivateKey(withBase64 base64String: String) throws -> PrivateKeyParameters
base64StringBase64-encoded key data
Return Value
New
PrivateKeyinstance. -
Creates a key with a PEM string.
Declaration
Swift
public class func createPrivateKey(withPEM pemString: String) throws -> PrivateKeyParameters
pemStringPEM-encoded key string
Return Value
New
PrivateKeyinstance. -
Creates a key with a PEM file.
Declaration
Swift
public class func createPrivateKey(withPEMNamed pemName: String, onPath path: String) throws -> PrivateKeyParameters
pemNameName of the PEM file
pathPath where the file is located.
Return Value
New
PrivateKeyinstance. -
Creates a key with a DER file.
Declaration
Swift
public class func createPrivateKey(withDERNamed derName: String, onPath path: String) throws -> PrivateKeyParameters
derNameName of the DER file
pathPath where the file is located.
Return Value
New
PrivateKeyinstance. -
Creates a key with a PEM file.
Declaration
Swift
public class func createPrivateKey(withPEMNamed pemName: String, in bundle: Bundle = Bundle.main) throws -> PrivateKeyParameters
pemNameName of the PEM file
bundleBundle in which to look for the PEM file. Defaults to the main bundle.
Return Value
New
PrivateKeyinstance. -
Creates a key with a DER file.
Declaration
Swift
public class func createPrivateKey(withDERNamed derName: String, in bundle: Bundle = Bundle.main) throws -> PrivateKeyParameters
derNameName of the DER file
bundleBundle in which to look for the DER file. Defaults to the main bundle.
Return Value
New
PrivateKeyinstance. -
Create a new RSA public/private key pair.
Declaration
Swift
public class func makeKeyPair(_ keySize: RSAKey.KeySize) throws -> (PrivateKey, PublicKey)Parameters
keySizeThe 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) -> StringParameters
derDataDatain DER format.typeType of key data.
Return Value
PEM
Datarepresentation. -
Get the Base64 representation of a PEM encoded string after stripping off the PEM markers.
Declaration
Swift
static func base64String(for pemString: String) throws -> StringParameters
pemStringStringcontaining PEM formatted data.Return Value
Base64 encoded
Stringcontaining 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 -> DataParameters
keyDataDatacontaining the public key with or without the x509 header.Return Value
Datacontaining the public with header (if present) removed. -
Add an X509 certificate header to key data.
Declaration
Swift
static func addX509CertificateHeader(for keyData: Data) -> DataParameters
keyDataData to add the header to.
Return Value
The modified key data.
CryptorRSA Class Reference