cryptobiu / libscapi

Comprehensive Open Source Library for Secure Multiparty Computation
MIT License
180 stars 66 forks source link

Cannot use DamgardJurik encryption #70

Closed lemonviv closed 5 years ago

lemonviv commented 5 years ago

I tried to use the DamgardJurik encryption (not exactly follow the documentation, just to test encryption and decryption now), the code is as follows:

include

include <libscapi/include/mid_layer/DamgardJurikEnc.hpp>

int main(int argc, char* argv[]) { // create a DamgardJurik encryption object DamgardJurikEnc encryptor;

// generate a key pair using the object DJKeyGenParameterSpec spec(128, 40); auto pair = encryptor.generateKey(spec); encryptor.setKey(pair.first, pair.second);

// create a plaintext BigIntegerPlainText plaintext("123"); shared_ptr

sharePlaintext = make_shared<BigIntegerPlainText>(plaintext); shared_ptr<AsymmetricCiphertext> cipher = encryptor.encrypt(sharePlaintext); shared_ptr<Plaintext> plain = encryptor.decrypt(cipher.get()); std::cout&lt;&lt;&quot;Decrypted plaintext is: &quot;&lt;&lt;plain.get()&lt;&lt;std::endl; return 0; }</p> </blockquote> <p>I compile the code, but received an error:</p> <blockquote> <p>DJPaillierExamples.cpp: In function ‘int main(int, char**)’: DJPaillierExamples.cpp:15:43: error: no matching function for call to ‘DamgardJurikEnc::generateKey(DJKeyGenParameterSpec&amp;)’ auto pair = encryptor.generateKey(spec);</p> </blockquote> <p>Actually the code inspection noticed: &quot;<strong>No matching member function for call to &quot;generateKey&quot;, candidate function not viable: requires 0 arguments, but 1 was provided.</strong>&quot; </p> <p>I am not sure whether I used it correctly. Any advice would be appreciated. Thank you.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/lemonviv"><img src="https://avatars.githubusercontent.com/u/9377547?v=4" />lemonviv</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>I used it in a wrong way, generateKey should be</p> <blockquote> <p>auto pair = encryptor.generateKey(&amp;spec);</p> </blockquote> <p>Then it works. The documentation might also need an update. Just close the issue. </p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>