# Using rust RSA library in ICP

**URL:** https://forum.dfinity.org/t/using-rust-rsa-library-in-icp/26377
**Category:** Rust
**Created:** [January 9, 2024, 8:44pm UTC](https://forum.dfinity.org/t/using-rust-rsa-library-in-icp/26377 "2024-01-09T20:44:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![agentDPS](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@agentDPS](https://forum.dfinity.org/u/agentDPS)
#### Post date: [January 9, 2024, 8:44pm UTC](https://forum.dfinity.org/t/using-rust-rsa-library-in-icp/26377/1 "2024-01-09T20:44:49Z")

</div>

So basically i am trying to create a wallet recovery protocol on ICP . That uses Vet keys and DKIM signatures … Issue is that i found a library called [viadkim](https://crates.io/crates/viadkim) which does the DKIM verification. Issue with this is that , it uses rsa crate , which isn’t support on ICP because i am getting this error when compiling  
to wasm32-target-target

```Compiling
error: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.10/src/lib.rs:285:9
    |
285 | / compile_error!("the wasm*-unknown-unknown targets are not supported by \
286 | | default, you may need to enable the \"js\" feature. \
287 | | For more information see: \
288 | | https://docs.rs/getrandom/#webassembly-support");
    | | ________________________________________________________________________ ^

```

So now , i would like to know if

1. Is there an rsa solution in ICP that does at least public key signature verification? ( thats all i need to do with rsa basically )
2. Is there any way to polyfill my way out of it ( i don’t know much of rust well enough , but in javascript land ,you polyfill your way to support a new run time )  
Some of the dependencies are also nested , how do remove or at least silent those ? . For example the library rand\_core is used by rsa and also pcks8.

---

<div class="post-metadata">

### Author: ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)
#### Post date: [January 10, 2024, 7:32am UTC](https://forum.dfinity.org/t/using-rust-rsa-library-in-icp/26377/2 "2024-01-10T07:32:12Z")

</div>

Hi @agentDPS,

You should be able to get [rsa 0.9.6 - Docs.rs](https://docs.rs/crate/rsa/0.9.6) working in canister. As your output suggests the issue is the getrandom dependency which attempts to access the randomness system API which is not available with `wasm*-unkown-unkown`.

For verification of a signature you don’t need any randomness, so for some crates it is enough to disable some of the default features, but it seems this doesn’t work for the rsa crate.

The next approach is to register a custom randomness function with getrandom. You can either define one that uses the IC’s randomness API or create a mock function because as mentioned before your use case doesn’t require randomness. For the latter approach you can have a look at the following example: [ic/rs/crypto/getrandom\_for\_wasm at master · dfinity/ic · GitHub](https://github.com/dfinity/ic/tree/master/rs/crypto/getrandom_for_wasm)

You need to add the getrandom crate explicitly with the `custom` feature enabled in your project  
`getrandom = { version = "0.2", features = ["custom"] }`

and then register a custom function like:

```auto
pub fn always_fail(_buf: &mut [u8]) -> Result<(), getrandom::Error> {
    Err(getrandom::Error::UNSUPPORTED)
}

getrandom::register_custom_getrandom!(always_fail);

```

For a random function that will always throw an error if it is called.

The last approach could be to utilize [GitHub - wasm-forge/ic-wasi-polyfill: The polyfill implementation for WASI functions in the IC environment](https://github.com/wasm-forge/ic-wasi-polyfill) and to enable the `js` feature as mentioned in the error, but I haven’t tried this myself.

---

<div class="post-metadata">

### Author: ![agentDPS](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@agentDPS](https://forum.dfinity.org/u/agentDPS)
#### Post date: [January 10, 2024, 7:54am UTC](https://forum.dfinity.org/t/using-rust-rsa-library-in-icp/26377/3 "2024-01-10T07:54:55Z")

</div>

> [@domwoe](#):
>
> li

Awesome thanks . i will try this and let you know soon

---

<div class="post-metadata">

### Author: ![officex](https://avatars.discourse-cdn.com/v4/letter/o/bcef8e/32.png) [@officex](https://forum.dfinity.org/u/officex)
#### Post date: [February 27, 2025, 12:05pm UTC](https://forum.dfinity.org/t/using-rust-rsa-library-in-icp/26377/4 "2025-02-27T12:05:09Z")

</div>

We are having same issue here:

> [@How to sign a message on client, Prove challenge in ICP canister](https://forum.dfinity.org/t/how-to-sign-a-message-on-client-prove-challenge-in-icp-canister/41187/9):
>
> I think this forum post is related: [Using rust RSA library in ICP](https://forum.dfinity.org/t/using-rust-rsa-library-in-icp/26377) Just for reference, our PR code is here with sample frontend code:

The linked example from [ic/rs/crypto/getrandom\_for\_wasm]([https://ic/rs/crypto/getrandom\_for\_wasm](https://ic/rs/crypto/getrandom_for_wasm) at master · dfinity/ic · GitHub) is now 404 not found, however there is a [new reference here](https://github.com/dfinity/ic/blob/0d96610b842ca721e50169c65bdfbc5d6d3d8b67/packages/ic-dummy-getrandom-for-wasm/README.md) with published crate [ic-dummy-getrandom-for-wasm](https://crates.io/crates/ic-dummy-getrandom-for-wasm).

Which solved my build problem - [sample code here](https://github.com/OfficeXApp/canisters-official/pull/26)
