Giter Site home page Giter Site logo

Comments (9)

dignifiedquire avatar dignifiedquire commented on July 17, 2024

from rsa.

wenjoy avatar wenjoy commented on July 17, 2024

@dignifiedquire Thanks for rapidly reply. I thought is the sha1 issue. But I cant figure out how to use sha1 in this crate.

use rsa::{PublicKey, RSAPublicKey, RSAPrivateKey, PaddingScheme};
use rand::rngs::OsRng;
use sha1::Sha1;

pub fn encrypt_(key: &[u8], plaintext: &[u8]) -> Vec<u8> {
  let mut rng = OsRng;
  let data = plaintext;
  let public_key = RSAPublicKey::from_pkcs8(key).expect("get private key error");
  // pkcs#1 padding
  // let padding = PaddingScheme::new_pkcs1v15_encrypt();
  let padding = PaddingScheme::new_oaep::<Sha1>();
  let enc_data = public_key.encrypt(&mut rng, padding, &data[..]).expect("failed to decrypt");
  enc_data
}

I tried this, but it complain. And I cant find out what other than Sha256 I can adapt, after go through the document.

from rsa.

tarcieri avatar tarcieri commented on July 17, 2024

Note: SHA-1 is cryptographically broken and unsuitable for use in any secure context.

from rsa.

wenjoy avatar wenjoy commented on July 17, 2024

@tarcieri Thanks. But I do need to interact with some legacy code. Is there any way I can use this lib to achieve?

from rsa.

dignifiedquire avatar dignifiedquire commented on July 17, 2024

@wenjoy what is the issue you are encountering with passing Sha1? We do have a test making sure the code does work with Sha1: https://github.com/RustCrypto/RSA/blob/master/src/key.rs#L904

from rsa.

wenjoy avatar wenjoy commented on July 17, 2024

@dignifiedquire I got this error:

the trait bound `sha1::Sha1: digest::Update` is not satisfied

the trait `digest::Update` is not implemented for `sha1::Sha1`

But the link you post inspired me to check the dependencies, then I solved it!

Thanks so much @dignifiedquire !

That's the thing. Previously my dependencies likes this:

sha1 = "*

after compare with this lib's , I found it should be this:

sha-1 = "*"

Now it works like a charm. But I have to say why its name so weird. Just following sha2 sha3 wouldn't be nice?

Anyway, thanks again @dignifiedquire.

from rsa.

newpavlov avatar newpavlov commented on July 17, 2024

@wenjoy
See the following remark in the hashes repository: https://github.com/RustCrypto/hashes#crate-names

from rsa.

dignifiedquire avatar dignifiedquire commented on July 17, 2024

glad to hear it is working now @wenjoy

from rsa.

wenjoy avatar wenjoy commented on July 17, 2024

@newpavlov Now that does make sense. Thanks buddy.

from rsa.

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.