RSAUtility

open class RSAUtility

RSA Encryption helper.

Upon initialization, you provide the name of the public key file (minus the .crt part) to the instance. This name is automatically used when it’s time to encrypt to read the key from the main Bundle. If your key is not in the main bundle, you can call loadBundledCertificate(from: <# Bundle #>) any time before calling encrypt(data:) to make the instance read the key from the given bundle.

  • The name of the bundled X509 public key certificate (without the .crt part).

    Declaration

    Swift

    open let publicCertificateFile: String
  • Designated initializer.

    Declaration

    Swift

    public init(publicCertificateFile certificateFile: String)

    Parameters

    publicCertificateFile

    Name of the bundled X509 public key certificate (without the .crt extension)

  • Encrypt given data using the receiver’s public key.

    Declaration

    Swift

    open func encrypt(data: Data) throws -> Data

    Parameters

    data

    The data to encrypt

    Return Value

    Encrypted data

  • Encrypt given data with the provided public key.

    Declaration

    Swift

    open func encrypt(data: Data, with key: SecKey) throws -> Data

    Parameters

    data

    The data to encrypt

    key

    The key to use for encryption

    Return Value

    Encrypted data

  • Tries to read data from publicCertificateFile in the given bundle, then forwards to loadPublicKey() to assign to publicKey.

    Declaration

    Swift

    public func loadBundledCertificate(from bundle: Bundle = Bundle.main) throws

    Parameters

    bundle

    The bundle to read the public key from; defaults to the main bundle