agens-no / EllipticCurveKeyPair

Sign, verify, encrypt and decrypt using the Secure Enclave
Other
709 stars 115 forks source link

I want to export the public key as X.509 DER with proper ASN.1 header / structure #32

Closed qadirsuh closed 6 years ago

qadirsuh commented 6 years ago

I need to export the public key as X.509 DER with proper ASN.1 header / structure

please give me an example.

I have a public key with format

-----BEGIN CERTIFICATE-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbEicao0J2djMo1Q3ECOuprI+XdZPJ13NeYyr1t/hp2VFe90SEAdv+LaJ6Qcffq7EdLUXCVekev7tBmAzEAU6FTYbjrWUeXFvsstWlUi+HfCowmRBzemCzMe7lzMiIZ49FTlVqxXHp2QWeummVHnZpLnzYSI/aQIZl9vf14cDKxQIDAQAB-----END CERTIFICATE-----

How to convert this in X.509 DER with proper ASN.1 header / structure

any help will be appreciated. thanks

hfossli commented 6 years ago

You have a certificate and want to export the public key? Is this a one time operation or does it need to be automated?

qadirsuh commented 6 years ago

Yes. want to export the public key. and its not the one time operation.

Actually I am following a documentation of loxone miniserver https://www.loxone.com/dede/wp-content/uploads/sites/2/2016/08/0903_Communicating-with-the-Miniserver.pdf

please see Page 5 of 21 and step number 2. i.e

  1. Acquire the Miniservers public key via “jdev/sys/getPublicKey​” -> {publicKey} a. Store on the client b. Format: X.509 encoded key in ANS.1
hfossli commented 6 years ago

Thanks for the clarification. As far as I can see the has nothing to do with elliptic curve key pairs (secp256r1). Instead it is all about AES and RSA. So it is out of scope for this repo.

When dealing with such keys I use to inspect them using tools like lapo.it. https://lapo.it/asn1js/#30819F300D06092A864886F70D010101050003818D00308189028181009B12271AA34276763328D50DC408EBA9AC8F977593C9D7735E632AF5B7F869D9515EF7448401DBFE2DA27A41C7DFABB11D2D45C255E91EBFBB41980CC4014E854D86E3AD651E5C5BECB2D5A5522F877C2A309910737A60B331EEE5CCC888678F454E556AC571E9D9059EBA69951E76692E7CD8488FDA408665F6F7F5E1C0CAC50203010001

Good luck! :) PM me if you want further assistance on an hourly fee.

hfossli commented 6 years ago

I would try https://github.com/btnguyen2k/swiftutils/blob/master/SwiftUtils/RSAUtils.swift or maybe https://github.com/RNCryptor/RNCryptor/blob/master/README.md

qadirsuh commented 6 years ago

Thanks for links :) BTW do you understanding the docs. points

  1. Generate a AES256 key -> {key} (Hex)
  2. Generate a random AES iv (16 byte) -> {iv} (Hex)

I am new to Encryption/Dycrptions and very new to AES. I am stuck on step 4 and 5. I have generated an AES key and AES iv and then converted it to (Hex) but I am not sure its correct or not. how to confirm this I have generated the correct keys. any free advice will be helpful :)

hfossli commented 6 years ago

I would then try to encrypt some data and try to decrypt it using same iv and key in openssl terminal.