digisign.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef DIGISIGN_HPP
  14. #define DIGISIGN_HPP
  15. #include "jiface.hpp"
  16. #include "pke.hpp"
  17. namespace cryptohelper
  18. {
  19. //Create base 64 encoded digital signature of given data
  20. jlib_decl bool digiSign(StringBuffer &b64Signature, size32_t dataSz, const void *data, const CLoadedKey &signingKey);
  21. //Verify the given data was used to create the given digital signature
  22. jlib_decl bool digiVerify(const char *b64Signature, size32_t dataSz, const void *data, const CLoadedKey &verifyingKey);
  23. //General purpose digital signature manager
  24. //Useful to sign data, so the consumer can be assured it has not been altered
  25. interface jlib_decl IDigitalSignatureManager : extends IInterface //Public/Private key message signer/verifyer
  26. {
  27. public:
  28. virtual bool isDigiSignerConfigured() const = 0;
  29. virtual bool isDigiVerifierConfigured() const = 0;
  30. virtual bool digiSign(StringBuffer & b64Signature, size32_t dataSz, const void *data) const = 0;//signs, using private key
  31. virtual bool digiSign(StringBuffer & b64Signature, const char *text) const = 0;
  32. virtual bool digiVerify(const char *b64Signature, size32_t dataSz, const void *data) const = 0;//verifies, using public key
  33. virtual bool digiVerify(const char *b64Signature, const char *text) const = 0;
  34. };
  35. //Uses the HPCCPublicKey/HPCCPrivateKey key files specified in environment.conf
  36. jlib_decl IDigitalSignatureManager * queryDigitalSignatureManagerInstanceFromEnv();
  37. //Create using the given key files
  38. jlib_decl IDigitalSignatureManager * createDigitalSignatureManagerInstanceFromFiles(const char *pubKeyFileName, const char *privKeyFileName, const char *passPhrase);
  39. //Create using the given PEM formatted keys
  40. jlib_decl IDigitalSignatureManager * createDigitalSignatureManagerInstanceFromKeys(const char *pubKeyString, const char *privKeyString, const char *passPhrase);
  41. //Create using preloaded keys.
  42. jlib_decl IDigitalSignatureManager * createDigitalSignatureManagerInstanceFromKeys(CLoadedKey *pubKey, CLoadedKey *privKey);
  43. } // namespace cryptohelper
  44. #endif // DIGISIGN_HPP