Closed adoley closed 7 years ago
Hey @adoley thanks for the question! You can load & decode a PEM-formatted key using the Key class. The ASN1 trait (which is used by the Key class) has a pemDecode function for this purpose. Refer to line 75 of the ASN1.php class file for the param & return value information or if you'd like to see how it works internally.
Since this trait is included in the Key class, all you would need to do is call this function from your instantiated key object, i.e.: $hexKeypair = $mykey->pemDecode('...pem key text...');
Let me know if that helps!
Hi, below are the code and exception
Fatal error: Uncaught exception 'Exception' with message 'Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data. OID is not for EC key. Value checked was "'8040410815'" in ASN1.php:155 Stack trace:
thrown in phactor/src/ASN1.php on line 155
require dirname(__FILE__).'/../vendor/autoload.php';
$key = new \Phactor\Key;
$hexKeypair = $key->decodePEM('-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgVfUclWgx951sJlMk rNW7DyqHXS2wwhhPWj9I3gsHpRWhRANCAAQlXxMH0e8pXwk7J/ZxG47gpNKwduaA Q+HThh0KmT3aCc7JMQhTy/ErXdCpUMfWYuJ69XXvbb9GDUYi1FVD6mYV -----END PRIVATE KEY-----');
Ok, so I apologize for not seeing the issue before but only PEM-formatted public keys are supported currently not private keys. I'll be adding support for private key pem data in a future release!
Thank you @ionux
Hi, is there a way to convert the below private key to hex(private_key_hex) so that I can use it in the function $signature = $sig->generate('my message to sign...', $info['private_key_hex'])
-----BEGIN PRIVATE KEY----- MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgVfUclWgx951sJlMk rNW7DyqHXS2wwhhPWj9I3gsHpRWhRANCAAQlXxMH0e8pXwk7J/ZxG47gpNKwduaA Q+HThh0KmT3aCc7JMQhTy/ErXdCpUMfWYuJ69XXvbb9GDUYi1FVD6mYV -----END PRIVATE KEY-----
And is there a way to load .pem file and get the public key in hex format.
Thanks.