Add RavelinEncrypt to your PodFile:
pod 'RavelinEncrypt', '1.1.2', :source => 'https://github.com/unravelin/Specs.git'
then, from the command line: pod install
Add RavelinEncrypt via Xcode, Add Package Dependency: a package manifest is available at: '[email protected]:unravelin/ravelin-encrypt-ios-xcframework-distribution.git'
SPM support available from version 1.1.0
To use the framework within your project, import RavelinEncrypt where required:
This repo provides three simple projects, showing the integration and usage of RavelinEncrypt:
- Swift using SPM
- Swift using Cocoapods
- Objective-C using Cocoapods
#import <RavelinEncrypt/RavelinEncrypt.h>
import RavelinEncrypt
The singleton RVNEncryption class should be access via the sharedInstance method. You must then provide your RSA key for card encryption.
// Instantiation for encryption
self.ravelinEncrypt = [RVNEncryption sharedInstance];
self.ravelinEncrypt.rsaKey = @"----|----";
// Instantiation for encryption
let ravelinEncrypt = RVNEncryption.sharedInstance()
ravelinEncrypt.rsaKey = "----|----"
Once initialised, you can use the sharedInstance directly to access methods and properties
// Directly
[[RVNEncryption sharedInstance]] methodName];
// Variable
RVNEncryption *ravelinEncrypt = [RVNEncryption sharedInstance];
// Directly
RVNEncryption.sharedInstance().methodName()
// Variable
let ravelinEncrypt = RVNEncryption.sharedInstance()
The SDK can be used to allow the secure sharing of card information with Ravelin whilst removing the need to handle PCI-compliant data.
When collecting the card details, we encrypt the values to send using the code method below. Validation is performed, confirming that expiry dates are valid and that the PAN is at least 13 characters. Should any validation checks fail, nil
is returned from the method. Pass an error by ref to determine the cause of failure if any occurs.
// Card details
NSString *pan = @"41111111111111";
NSString *month = @"10";
NSString *year = @"27";
NSString *cardHolder = @"Mr John Doe";
// Error handling
NSError *error;
// Encrypt
NSDictionary *encryptionPayload = [[RVNEncryption sharedInstance] encrypt:pan month:month year:year nameOnCard:cardHolder error:&error];
if(!error) {
NSLog(@"Ravelin encryption payload: %@",encryptionPayload);
// Send to your servers
} else {
NSLog(@"Ravelin encryption error %@", error.localizedDescription);
}
var error:NSError? = nil
let encryptionPayload = RVNEncryption.sharedInstance().encrypt("41111111111111", month: "10", year: "27", nameOnCard: "Mr John Doe", error: &error)
if let error = error {
print("Ravelin encryption error \(error.localizedDescription)")
} else {
print("Ravelin Encryption payload: \(encryptionPayload as AnyObject)")
// Send to your servers
}
What follows is a simple end-to-end example of using the Ravelin Framework within a View.
#import "ViewController.h"
#import <UIKit/UIKit.h>
#import <RavelinEncrypt/RavelinEncrypt.h>
@interface ViewController ()
@property (strong, nonatomic) RVNEncryption *ravelinEncrypt;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self useEncrypt];
}
- (void)useEncrypt {
// Make RavelinEncrypt instance with rsa key
self.ravelinEncrypt = [RVNEncryption sharedInstance];
self.ravelinEncrypt.rsaKey = @"----|---------";
// Encrypt customer card details, ready for sending for payment
NSError *error;
NSDictionary *encryptionPayload = [self.ravelinEncrypt encrypt:@"41111111111111" month:@"10" year:@"27" nameOnCard:@"Mr John Doe" error:&error];
if(!error) {
NSLog(@"Ravelin Encryption payload: %@", encryptionPayload);
} else {
NSLog(@"Ravelin encryption error %@", error.localizedDescription);
}
}
@end
import UIKit
import RavelinEncrypt
class ViewController: UIViewController {
private var ravelinEncrypt = RVNEncryption.sharedInstance()
override func viewDidLoad() {
super.viewDidLoad()
useEncryot()
}
func useEncrypt() {
// set up ravelin encryption RSA key
ravelinEncrypt.rsaKey = "----|----"
// Encrypt customer card details, ready for sending for payment
var error:NSError? = nil
let encryptionPayload = ravelinEncrypt.encrypt("41111111111111", month: "10", year: "20", nameOnCard: "Mr John Doe", error: &error)
if let error = error {
print("Ravelin encryption error \(error.localizedDescription)")
} else {
print("Ravelin Encryption payload: \(encryptionPayload as AnyObject)")
// Send to server
}
}
}
Get the instantiated RVNEncryption singleton
Return value
The singleton instance of the class
Generates encryption payload ready for sending to Ravelin
Parameters
Parameter | Type | Description |
---|---|---|
pan | String | A string representation of the long card number |
month | String | Expiry month of card (1-12) |
year | String | Expiry year (2 or 4 digit) |
nameOnCard | String | The customer name on the card |
error | Object | Passed as reference |
Return value
Dictionary containing methodType, aesKeyCiphertext, cardCiphertext, algorithm, keyIndex and ravelinSDKVersion
The public RSA key from your dashboard
License information can be found here