1

First of all version of Botan I'm using is Botan-1.10.9 And I'm writing a managed wrapper in Visual C++

Following this example, I'm trying to create a SymmetricKey from the hash of a string so I can pass it into the fe1_encrypt method of the FPE module

Signature of fe1_encrypt is

BigInt FPE::fe1_encrypt(const BigInt &n, const BigInt &X, const SymmetricKey &key, const std::vector<byte> &tweak)

I want the value I pass into the key parameter to be hash of the plaintext (not possibility to decrypt) So really I don't care about it being a SymmetricKey, just need that type because the method requires it as a parameter.

But in their example they have passed the SymmetricKey their hash method that returns an std:vector

However there is no constructor for SymmetricKey that takes this type.

Anyone have any ideas?

EDIT: I tried this with no luck

std::vector<byte> re = SHA_1(plaintextAsString);
Botan::OctetString key(re, re.size());

ERROR

Error 15 error C2664: 'Botan::OctetString::OctetString(Botan::RandomNumberGenerator &,size_t)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'Botan::RandomNumberGenerator &'

erotavlas
  • 4,274
  • 4
  • 45
  • 104

1 Answers1

1

In the documentation, SymmetricKey (which is just a typedef for OctetString) can take a byte array and length as constructor. Alternatively, you can encode the key as a hex string. If you already have the key as std::vector<byte>, then this should suffice:

std::vector<byte> keybytes;
// ...fill the vector...

SymmetricKey key( keybytes.data(), keybytes.size() );

Later versions of Botan define another constructor OctetString (const std::vector<byte> &in).

paddy
  • 60,864
  • 6
  • 61
  • 103
  • OMG Thanks so much!. I was stuck for so long. It was the data() method I was missing. This works. – erotavlas Jun 23 '15 at 21:00
  • 1
    Instead of `keybytes.data()`, you might also commonly see `&keybytes[0]` used when someone is obtaining a pointer to the start of a vector's data. I prefer the `data` method. – paddy Jun 23 '15 at 21:05