This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private byte[] signWithPrivateKey(byte[] bytes, String privateKey) throws Exception { | |
Signature signature = Signature.getInstance("SHA256withRSA", "SC"); | |
signature.initSign(Crypto.getRSAPrivateKeyFromString(privateKey)); | |
signature.update(bytes); | |
return signature.sign(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static KeyPair generateRSAKeyPair() throws Exception { | |
SecureRandom random = new SecureRandom(); | |
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(KEY_SIZE, RSAKeyGenParameterSpec.F4); | |
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "SC"); | |
generator.initialize(spec, random); | |
return generator.generateKeyPair(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static PublicKey getRSAPublicKeyFromString(String apiKey) throws Exception{ | |
KeyFactory keyFactory = KeyFactory.getInstance("RSA", "SC"); | |
byte[] publicKeyBytes = Base64.decode(apiKey.getBytes("UTF-8"), Base64.DEFAULT); | |
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(publicKeyBytes); | |
return keyFactory.generatePublic(x509KeySpec); | |
} | |
public static PrivateKey getRSAPrivateKeyFromString(String key) throws Exception { | |
byte [] clear = Base64.decode(key, Base64.DEFAULT); | |
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(clear); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(NSString *)encryptRSA:(NSString *)plainTextString key:(SecKeyRef)publicKey { | |
size_t cipherBufferSize = SecKeyGetBlockSize(publicKey); | |
uint8_t *cipherBuffer = malloc(cipherBufferSize); | |
uint8_t *nonce = (uint8_t *)[plainTextString UTF8String]; | |
SecKeyEncrypt(publicKey, | |
kSecPaddingOAEP, | |
nonce, | |
strlen( (char*)nonce ), | |
&cipherBuffer[0], | |
&cipherBufferSize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(NSString *)decryptRSA:(NSString *)cipherString key:(SecKeyRef) privateKey { | |
size_t plainBufferSize = SecKeyGetBlockSize(privateKey); | |
uint8_t *plainBuffer = malloc(plainBufferSize); NSData *incomingData = [NSData dataFromBase64String:cipherString]; | |
uint8_t *cipherBuffer = (uint8_t*)[incomingData bytes]; | |
size_t cipherBufferSize = SecKeyGetBlockSize(privateKey); | |
SecKeyDecrypt(privateKey, | |
kSecPaddingOAEP, | |
cipherBuffer, | |
cipherBufferSize, | |
plainBuffer, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSData *)getSignatureBytes:(NSData *)plainText withPrivateKey:(SecKeyRef)privateKey | |
{ | |
OSStatus sanityCheck = noErr; | |
NSData * signedHash = nil; | |
uint8_t *signedHashBytesSize = SecKeyGetBlockSize(privateKey); | |
size_t signedHashBytes = malloc( signedHashBytesSize * sizeof(uint8_t) ); | |
memset((void *)signedHashBytes, 0x0, signedHashBytesSize); | |
sanityCheck = SecKeyRawSign(privateKey, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(void)generateKeyPairWithPublicTag:(NSString *)publicTagString privateTag:(NSString *)privateTagString { | |
NSMutableDictionary *privateKeyAttr = [[NSMutableDictionary alloc] init]; | |
NSMutableDictionary *publicKeyAttr = [[NSMutableDictionary alloc] init]; | |
NSMutableDictionary *keyPairAttr = [[NSMutableDictionary alloc] init]; | |
NSData *publicTag = [publicTagString dataUsingEncoding:NSUTF8StringEncoding]; | |
NSData *privateTag = [privateTagString dataUsingEncoding:NSUTF8StringEncoding]; | |
SecKeyRef publicKey = NULL; | |
SecKeyRef privateKey = NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://api.launchkey.com/v1/ping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST https://api.launchkey.com/v1/auths \ | |
-d app_key=1234567890 \ | |
--data-urlencode secret_key=SECRET_KEY \ | |
--data-urlencode signature=SIGNATURE \ | |
-d username=USERNAME \ | |
-d session=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://api.launchkey.com/v1/poll \ | |
-d app_key=1234567890 \ | |
--data-urlencode secret_key=SECRET_KEY \ | |
--data-urlencode signature=SIGNATURE \ | |
-d auth_request=AUTH_REQUEST |