SwiftyRSA icon indicating copy to clipboard operation
SwiftyRSA copied to clipboard

Generating Public Key from custom Data made from modulus and exponent

Open diascov opened this issue 7 years ago • 3 comments

Hi there!

First of all I would like to say I'm new in programming so maybe I could ask some weird q =D

I would like to generate Public Key with data made with public key modulus and exponent.

screen shot 2018-01-24 at 11 35 06

let modData = modulus.data(using: .utf8)! let expData = exponent.data(using: .utf8)! let dataArray = [modData, expData] let publicKeyData = NSKeyedArchiver.archivedData(withRootObject: dataArray)

publicKeyData - is data for encryption as I read from java and C# examples.

my q is why I'm receiving this error from : try PublicKey(data: publicKeyData) SwiftyRSA.SwiftyRSAError.asn1ParsingFailed same with base64encoded Data

I could create Public Key only from Der or Pem files created from openssl commands to send public key to another users. But how can I manage received public key from server and create SecKey to encrypt password string?

diascov avatar Jan 24 '18 09:01 diascov

@petrishenkoS @Negative3131 Thanks for opening an issue! Sorry about the delay too.

I'm not sure whether sending raw modulus & exponents is common practice but I haven't seen this used in the wild so far, and the apple SDK doesn't seem to offer such a functionality. I'm open to contributions that would add this ability, just tag me on the PR.

In the meantime, I would recommend sending keys in a PEM format (which is just DER but base64 encoded). This is perfect for http transfers since you can send a string representation as opposed to binary data.

ldiqual avatar Mar 07 '18 01:03 ldiqual

At present, it is necessary to use index and modulus to generate public key. Swift has not found a suitable solution at present.

manfengjun avatar May 25 '18 01:05 manfengjun

so how to solve this issue of asn1parsingfailed, please help

yogendrakarekar avatar Sep 21 '19 07:09 yogendrakarekar