Coder Social home page Coder Social logo

Comments (6)

TheBosZ avatar TheBosZ commented on July 18, 2024 4

I think you misunderstood the question.

The question is how to use your library to encrypt a plain text using only the public key.

The RSA class requires both the public and private key, which is fine, except that encryption should only require the public key while decryption should only require the private key.

from encrypt.

leocavalcante avatar leocavalcante commented on July 18, 2024 1

Oh, sure, right. Now it makes senses.
I'll work on that. Probably the API would look like Encrypter(RSA(publicKey, null));.
Then null checks internally, just in case.

from encrypt.

leocavalcante avatar leocavalcante commented on July 18, 2024 1

Here we go.

final encrypter = Encrypter(RSA(publicKey: publicKey, privateKey: privateKey));

If you are just encrypting or just decrypting, you can ignore the respective privateKey and publicKey. Trying the encrypt without a public key or decrypt without a private key will throw a StateError.

This was addressed on v2.0. You can use it right now by referencing it on pub:

dependencies:
  kittens:
    git:
      url: git://github.com/leocavalcante/encrypt.git
      ref: v2.0

from encrypt.

TheBosZ avatar TheBosZ commented on July 18, 2024 1

This works perfectly! I had to dig a little bit to figure out that I needed to construct an Encrypted object using fromBase64, but now it's working as I want it to!

Thanks for a useful utility!

from encrypt.

leocavalcante avatar leocavalcante commented on July 18, 2024

Hm 🤔
The ideia behind RSA is to be asymmetric, a public key for encryption and a private key for decryption.
If you want to use a single key, you should use a symmetric system like AES or Salsa20.

from encrypt.

leocavalcante avatar leocavalcante commented on July 18, 2024

Please, note that v2.0 returns an Encrypted object now on encrypt() method.
You can get the hexdecimal representation using the base16 getter:

print(encrypted.base16);

And there is also a getter for a base64 representation:

print(encrypted.base64);

Or you can do whatever you want with the raw bytes:

print(encrypted.bytes);

from encrypt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.