Reputation: 77
In Crypto++, I'm trying to use a public key generated by ECDH to encrypt a message with ECIES. Is that possible? The key is stored in a SecByteBlock. I've tried two options: 1) reading the bytes directly via StringSource; 2) creating an Integer and encoding it to BER, then trying to decode it in the public key. None of these options worked, both generate a BER format exception.
What might I be doing wrong? Is there any other way to set the ECIES encryptor public key's bytes directly?
Thanks!
Upvotes: 0
Views: 647
Reputation: 77
For anyone wondering, what I was actually trying to do was this... Suppose that at some point a key pair was generated in the following way:
ECDH<ECP>::Domain domain(some_curve);
SecByteBlock prv(domain.PrivateKeyLength()), pub(domain.PublicKeyLength());
domain.GenerateKeyPair(AutoSeededRandomPool(), prv, pub);
Later, given just the raw (bytes) representation, if you need to load these keys for encryption, you could do:
auto& params = domain.GetGroupParameters();
ECIES<ECP>::PrivateKey prv_key;
ECIES<ECP>::PublicKey pub_key;
prv_key.Initialize(params, Integer(prv.begin(), prv.size());
pub_key.Initialize(params, params.DecodeElement(pub, true));
And then create Encryptor/Decryptor as needed:
ECIES<ECP>::Encryptor encptor(pub_key);
ECIES<ECP>::Decryptor decptor(prv_key);
Anyway, thanks for the help in the comments, it put me in the right direction to find the answer!
Upvotes: 2