public-key-encryption

How do I encode an unmanaged<SecKey> to base64 to send to another server?

一世执手 提交于 2019-11-28 05:23:19
问题 I'm trying to use key pair encryption to validate identity between my app and my PHP server. To do this I need to send the public key over to the server after I generate it in my app. if let pubKey = NSData(base64EncodedData: publicKey, options: NSDataBase64DecodingOptions.allZeros)! { println(pubKey) } publicKey is of type Unmanaged<SecKey> . The error I'm getting in the above code is: Extra argument 'base64EncodedData' in call How would I do this? Is there a better way? Edit: This is how

Can PHP OpenSSL generate private/public key/certificate pairs?

▼魔方 西西 提交于 2019-11-28 04:21:02
问题 I wonder if PHP's OpenSSL extension can be used to generate private/public key/certificate pairs? 回答1: Sure, use openssl_pkey_new: $privateKey = openssl_pkey_new(array('private_key_bits' => 2048)); $details = openssl_pkey_get_details($privateKey); $publicKey = $details['key']; You can export the keys with openssl_pkey_export or openssl_pkey_export_to_file. 回答2: I really appreciate the answer from phihag but was still struggling. Ultimately, this helped: $privateKeyResource = openssl_pkey_new(

RSA code in matlab

自作多情 提交于 2019-11-28 03:54:36
问题 I want to encrypt a message such as 'HELO1234 and then decrypt to get the original one.I have written RSA code in matlab which is not working correctly. PARAMETER CALCULATION temp=1; range=1:10; k=isprime(range) prime_mat=range(find(k)) p=randsample(prime_mat,1); q=randsample(prime_mat,1); if(p~=q) n=p*q; phi_n=(p-1)*(q-1); u=1:phi_n -1; end while temp enckey=randsample(u,1); deckey=randsample(u,1); if(enckey~=deckey) if(gcd(enckey,phi_n)~=1 ... && gcd(deckey,phi_n)~=1 ... &&gcd(enckey*deckey

configuring SSLContext using existing SSL key/certificate pair in java (JSSE API)

烈酒焚心 提交于 2019-11-28 02:20:59
问题 I am working on a java-project where I should implement the SSL-protokol on the server-side. Well, this is the first time I will use SSL in my application, so I read a lot about ssl/tls and now I want to implement something in java. I will implement this process using JSSE API: 1) client will connect to me 2) I will make authentification with my pubic key certificate. I means that I will send the client a public key and its corresponding certificate 3) the client encrypt the secret-key using

Generate RSA Public Key from Modulus and Exponent

允我心安 提交于 2019-11-28 01:11:47
问题 I'm looking to generate a rsa public key (pem) from both the modulus and exponent in Objective-C. This function can be done in Java by the following; PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, exponent)); Although I'm having some trouble writing this for the iOS platform. Am aware of OpenSSL , but I couldn't find a successful method and am still unable to generate this key. Also took a look at SCZ-BasicEncodingRules-iOS but this returns a

Encrypting large files using a public key

故事扮演 提交于 2019-11-27 23:52:16
问题 I need to encrypt a 100KB file using a public key. I've been reading some posts claiming that it is not practical to directly encrypt large files using a public key, and that the preferred method is to encrypt the file using a symmetric key and then encrypt this symmetric key using the public key. It seems that a naive solution would be to break the large file to pieces and encrypt each one of them using the same public key. My question is whether and why this solution is wrong? 回答1: The

How do I obtain the public key from an ECDSA private key in OpenSSL?

谁都会走 提交于 2019-11-27 22:34:51
I am providing this sample application to show my problem #include <stdio.h> #include <stdlib.h> #include <openssl/ec.h> #include <openssl/bn.h> int main() { EC_KEY *pkey = NULL; EC_POINT *pub_key = NULL; const EC_GROUP *group = NULL; BIGNUM start; BIGNUM *res; BN_CTX *ctx; BN_init(&start); ctx = BN_CTX_new(); res = &start; BN_hex2bn(&res,"3D79F601620A6D05DB7FED883AB8BCD08A9101B166BC60166869DA5FC08D936E"); pkey = EC_KEY_new_by_curve_name(NID_secp256k1); group = EC_KEY_get0_group(pkey); pub_key = EC_POINT_new(group); EC_KEY_set_private_key(pkey, res); assert(EC_POINT_bn2point(group,res, pub_key

Using Base64 encoded Public Key to verify RSA signature

江枫思渺然 提交于 2019-11-27 22:05:27
In a nutshell, this is my problem: private string publicKeyString = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVGUzbydMZS+fnkGTsUkDKEyFOGwghR234d5GjPnMIC0RFtXtw2tdcNM8I9Qk+h6fnPHiA7r27iHBfdxTP3oegQJWpbY2RMwSmOs02eQqpKx4QtIjWqkKk2Gmck5cll9GCoI8AUAA5e0D02T0ZgINDmo5yGPhGAAmqYrm8YiupwQIDAQAB"; /* Some transformation required, using publicKeyString to initiate a new RSACryptoServiceProvider object */ //for now: RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] selfComputedHash = new byte[]; //left out of the example byte[] signature = new byte[]; bool result = rsa.VerifyHash

Can I get the modulus or exponent from a SecKeyRef object in Swift?

回眸只為那壹抹淺笑 提交于 2019-11-27 21:10:37
In Swift, I created a SecKeyRef object by calling SecTrustCopyPublicKey on some raw X509 certificate data. This is what this SecKeyRef object looks like. Optional(<SecKeyRef algorithm id: 1, key type: RSAPublicKey, version: 3, block size: 2048 bits, exponent: {hex: 10001, decimal: 65537}, modulus: <omitted a bunch of hex data>, addr: 0xsomeaddresshere>) Basically, this SecKeyRef object holds a whole bunch of information about the public key, but there seems to be no way to actually convert this SecKeyRef into a string, NSData , or anything else (this is my goal, is just to get a base64 public

SSL Alternative - encrypt password with JavaScript submit to PHP to decrypt

烂漫一生 提交于 2019-11-27 20:55:48
I'm building a website and my payment methods will be Google Checkout and Paypal. There will be links/buttons which will redirect the user to the secure Google/Paypal sites for processing the payments. This means I do not need the $150/year added expense and complexity of installing SSL certificates for my site. However I would like to encrypt user's passwords as they are logging in so that if they are on a network some malicious person running FireSheep etc can't read the user's actual password as it is being sent to the server. The rest of the site doesn't need encryption as it's not really