### Install SwiftyRSA with Carthage Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Use this command to install SwiftyRSA using Carthage. ```bash github "TakeScoop/SwiftyRSA" ``` -------------------------------- ### Install SwiftyRSA with Cocoapods Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Use this command to install SwiftyRSA using Cocoapods. ```bash pod 'SwiftyRSA' ``` -------------------------------- ### Create PublicKey from SecKey reference Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PublicKey object from a SecKey reference. ```swift let publicKey = try PublicKey(reference: secKey) ``` -------------------------------- ### Create PrivateKey from SecKey reference Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PrivateKey object from a SecKey reference. ```swift let privateKey = try PrivateKey(reference: secKey) ``` -------------------------------- ### Create PublicKey from Data Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PublicKey object from raw Data. ```swift let publicKey = try PublicKey(data: data) ``` -------------------------------- ### Create PublicKey from PEM file Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PublicKey object from a PEM encoded file. Requires the file to be named 'public' in the project. ```swift let publicKey = try PublicKey(pemNamed: "public") ``` -------------------------------- ### Create PrivateKey from Data Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PrivateKey object from raw Data. ```swift let privateKey = try PrivateKey(data: data) ``` -------------------------------- ### Create PublicKey from DER file Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PublicKey object from a DER encoded file. Requires the file to be named 'public' in the project. ```swift let publicKey = try PublicKey(derNamed: "public") ``` -------------------------------- ### Create PrivateKey from PEM file Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PrivateKey object from a PEM encoded file. Requires the file to be named 'private' in the project. ```swift let privateKey = try PrivateKey(pemNamed: "private") ``` -------------------------------- ### Create PrivateKey from DER file Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PrivateKey object from a DER encoded file. Requires the file to be named 'private' in the project. ```swift let privateKey = try PrivateKey(derNamed: "private") ``` -------------------------------- ### Create PublicKey from Base64 string Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PublicKey object from a Base64 encoded string. ```swift let publicKey = try PublicKey(base64Encoded: base64String) ``` -------------------------------- ### Create PublicKey from PEM Named String Source: https://github.com/takescoop/swiftyrsa/blob/master/CHANGELOG.md Demonstrates creating a PublicKey instance from a PEM-encoded string identified by a name. This is part of the architecture overhaul in version 1.0.0. ```swift PublicKey(pemNamed: "public") ``` -------------------------------- ### Create PrivateKey from Base64 string Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PrivateKey object from a Base64 encoded string. ```swift let privateKey = try PrivateKey(base64Encoded: base64String) ``` -------------------------------- ### Create PublicKey from PEM string Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PublicKey object from a PEM encoded string. ```swift let publicKey = try PublicKey(pemEncoded: str) ``` -------------------------------- ### Read Multiple Public Keys from File Source: https://github.com/takescoop/swiftyrsa/blob/master/CHANGELOG.md Utilize the `publicKeysFromString()` method to efficiently load multiple public keys from a single input file. This functionality was introduced in version 0.4.0. ```swift publicKeysFromString() ``` -------------------------------- ### Integrate SwiftyRSA with Objective-C Source: https://github.com/takescoop/swiftyrsa/blob/master/CHANGELOG.md To use SwiftyRSA with Objective-C, specify the ObjC pod in your Podfile. Other integration methods like Carthage are unaffected. ```ruby pod 'SwiftyRSA/ObjC' ``` -------------------------------- ### Create PrivateKey from PEM string Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Initializes a PrivateKey object from a PEM encoded string. ```swift let privateKey = try PrivateKey(pemEncoded: str) ``` -------------------------------- ### Add X.509 Header to Public Key Data Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Prepends the X.509 header to raw public key data, making it a standard PEM-formatted public key. ```swift let publicKey = PublicKey(data: data) let publicKeyData = try publicKey.data() let publicKey_with_X509_header = try SwiftyRSA.prependX509KeyHeader(keyData: publicKeyData) ``` -------------------------------- ### Export Key as PEM, Base64, or Data Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Exports a PublicKey or PrivateKey object into PEM string, Base64 string, or raw Data format. ```swift let pem = try key.pemString() let base64 = try key.base64String() let data = try key.data() let reference = key.reference let originalData = key.originalData ``` -------------------------------- ### Encrypt String with Public Key Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Encrypts a clear string using a public key in PEM format. Requires the public key to be named 'public' in the project. ```swift do { let publicKey = try PublicKey(pemNamed: "public") let str = "Clear String" let clear = try ClearMessage(string: str, using: .utf8) let encrypted = try clear.encrypted(with: publicKey, padding: .PKCS1) let data = encencrypted.data print(data) let base64String = encrypted.base64String print(base64String) } catch { print(error) } ``` -------------------------------- ### Add Carthage Support for SwiftyRSA Source: https://github.com/takescoop/swiftyrsa/blob/master/CHANGELOG.md This entry indicates the addition of Carthage support for SwiftyRSA, addressing compiler warnings specific to Carthage integration. ```swift #import ``` -------------------------------- ### Generate RSA Key Pair in Swift Source: https://github.com/takescoop/swiftyrsa/blob/master/CHANGELOG.md Use the `generateRSAKeyPair` function to create a new RSA key pair. This feature was added to support Swift 4.1 and Xcode 9.3. ```swift SwiftyRSA.generateRSAKeyPair ``` -------------------------------- ### Generate PEM Public and Private RSA Keys Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Generate RSA keys using ssh-keygen. Ensure to use the -m PEM flag for PEM format. The output keys will be in `~/public.pem` and `~/private.pem`. ```bash $ ssh-keygen -t rsa -m PEM -f ~/mykey -N '' $ cat ~/mykey > ~/private.pem $ ssh-keygen -f ~/mykey.pub -e -m pem > ~/public.pem ``` -------------------------------- ### Verify Signature with PublicKey Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Verifies a digital signature against a clear message using a public key and SHA1 digest. ```swift let signature = try Signature(base64Encoded: "AAA===") let isSuccessful = try clear.verify(with: publicKey, signature: signature, digestType: .sha1) ``` -------------------------------- ### Generate RSA Key Pair Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Generates a new RSA key pair with a specified bit size (e.g., 2048 bits). ```swift let keyPair = SwiftyRSA.generateRSAKeyPair(sizeInBits: 2048) let privateKey = keyPair.privateKey let publicKey = keyPair.publicKey ``` -------------------------------- ### Encrypt Clear Message with PublicKey Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Encrypts a clear message using a provided PublicKey object with PKCS1 padding. ```swift let str = "Clear Text" let clear = try ClearMessage(string: str, using: .utf8) let encrypted = try clear.encrypted(with: publicKey, padding: .PKCS1) let data = encrypted.data let base64String = encrypted.base64Encoded ``` -------------------------------- ### Sign Clear Message with PrivateKey Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Signs a clear message using a private key and SHA1 digest. Returns the signature as Data and Base64 string. ```swift let clear = try ClearMessage(string: "Clear Text", using: .utf8) let signature = clear.signed(with: privateKey, digestType: .sha1) let data = signature.data let base64String = signature.base64String ``` -------------------------------- ### Strip X.509 Header from Public Key Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Use this function to manually strip the X.509 header from a public key Data. Note that creating a PublicKey instance automatically performs this. ```swift let publicKey_headerLess: Data = try SwiftyRSA.stripKeyHeader(keyData: publicKey_with_X509_header) ``` -------------------------------- ### Decrypt Encrypted Message with Private Key Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Decrypts a Base64 encoded encrypted message using a private key in PEM format. Requires the private key to be named 'private' in the project. ```swift let privateKey = try PrivateKey(pemNamed: "private") let encrypted = try EncryptedMessage(base64Encoded: "AAA===") let clear = try encrypted.decrypted(with: privateKey, padding: .PKCS1) // Then you can use: let data = clear.data let base64String = clear.base64String let string = clear.string(using: .utf8) ``` -------------------------------- ### Decrypt Encrypted Message with PrivateKey Source: https://github.com/takescoop/swiftyrsa/blob/master/README.md Decrypts an encrypted message using a provided PrivateKey object with PKCS1 padding. ```swift let encrypted = try EncryptedMessage(base64Encoded: base64String) let clear = try encrypted.decrypted(with: privateKey, padding: .PKCS1) let data = clear.data let base64String = clear.base64Encoded let string = try clear.string(using: .utf8) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.