# I am implementing IBE encryption getting error while using system\_api

**URL:** <https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402>\
**Category:** Rust\
**Created:** [August 23, 2024, 9:36am UTC](https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402 "2024-08-23T09:36:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rachit2323](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rachit2323/32/19417_2.png) [@Rachit2323](https://forum.dfinity.org/u/Rachit2323)\
**Post date:** [August 23, 2024, 9:36am UTC](https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402/1 "2024-08-23T09:36:32Z")

</div>

Error: Failed while trying to deploy canisters.  
Caused by: Failed while trying to install all canisters.  
Caused by: Failed to install wasm module to canister ‘system\_api’.  
Caused by: Failed during wasm installation call  
Caused by: The replica returned a rejection error: reject code CanisterError, reject message Error from Canister gf4a7-g4aaa-aaaaa-qaarq-cai: Canister’s Wasm module is not valid: Wasm module has an invalid import section. Module imports function ‘\_\_wbindgen\_describe’ from ‘ **wbindgen\_placeholder** ’ that is not exported by the runtime…  
This is likely an error with the compiler/CDK toolchain being used to build the canister. Please report the error to IC devs on the forum: [https://forum.dfinity.org](https://forum.dfinity.org) and include which language/CDK was used to create the canister., error code None

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [August 23, 2024, 9:44am UTC](https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402/2 "2024-08-23T09:44:30Z")

</div>

> [@Module imports function '\_\_wbg\_now\_2e07eedfb4ac9dbe' from '\_\_wbindgen\_placeholder\_\_' that is not exported by the runtime](https://forum.dfinity.org/t/module-imports-function-wbg-now-2e07eedfb4ac9dbe-from-wbindgen-placeholder-that-is-not-exported-by-the-runtime/22083/2):
>
> Suggested reading: [Ideas on tracking down "Module imports function '\_\_wbindgen\_describe' from '\_\_wbindgen\_placeholder\_\_' that is not exported by the runtime." - #3 by GLdev](https://forum.dfinity.org/t/ideas-on-tracking-down-module-imports-function-wbindgen-describe-from-wbindgen-placeholder-that-is-not-exported-by-the-runtime/17639/3)[Module imports function '\_\_wbindgen\_describe' from '\_\_wbindgen\_placeholder\_\_' that is not exported by the runtime - #2 by GLdev](https://forum.dfinity.org/t/module-imports-function-wbindgen-describe-from-wbindgen-placeholder-that-is-not-exported-by-the-runtime/11545/2)[Using random module from Rust](https://forum.dfinity.org/t/using-random-module-from-rust/9002)

---

<div class="post-metadata">

**Author:** ![Rachit2323](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rachit2323/32/19417_2.png) [@Rachit2323](https://forum.dfinity.org/u/Rachit2323)\
**Post date:** [September 2, 2024, 12:42pm UTC](https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402/3 "2024-09-02T12:42:19Z")

</div>

Got the fix , Use below in cargo.toml in place of  
`getrandom = { version = "0.2", features = ["js"] }`

as

```auto
getrandom = { version = "0.2", features = ["custom"] }

```

---

<div class="post-metadata">

**Author:** ![sea-snake](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/sea-snake/32/7243_2.png) [@sea-snake](https://forum.dfinity.org/u/sea-snake)\
**Post date:** [September 2, 2024, 2:04pm UTC](https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402/4 "2024-09-02T14:04:31Z")

</div>

“custom” also means you need to implement this custom method.

If “getrandom” is a child dependency that is never actually invoked, you can implement it as a method that will always fail as seen here [cdk-rs/examples/chess/src/chess\_rs/getrandom\_fail.rs at 0b14facb80e161de79264c8f88b1a0c8e18ffcb6 · dfinity/cdk-rs · GitHub](https://github.com/dfinity/cdk-rs/blob/0b14facb80e161de79264c8f88b1a0c8e18ffcb6/examples/chess/src/chess_rs/getrandom_fail.rs)

In case “getrandom” needs to actually return random data instead of throwing an error you have two options:

1. See if the library that depends on “getrandom” allows you to implement your own source of random bytes and pass it in as argument, in which case you can asynchronously call the system canister to get random bytes. In this case the “getrandom” library will never get invoked and above fail implementation can be used to make things compile.

2. Use a synchronous PRNG implementation to write the custom “getrandom” method. Keep in mind this significantly less secure since it relies on a random seed (thats passed to PRNG) and the PRNG state to be stored in the canister state.

Overall, both implementation options do not work for query methods since either you can’t make inter canister calls (option 1) or update state (option 2). So make sure to implement an update method for either approach.

Make sure to test your canister, to be truly certain your implementation is using random bytes correctly and is secure!

Maybe this topic should be documented somewhere in the Rust SDK docs since it seems a recurring question on the forums 😅

---

<div class="post-metadata">

**Author:** ![derak-isaack](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/derak-isaack/32/22618_2.png) [@derak-isaack](https://forum.dfinity.org/u/derak-isaack)\
**Post date:** [June 14, 2025, 6:10pm UTC](https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402/5 "2025-06-14T18:10:15Z")

</div>

So what might be the best way to enable wasm32-uknown-unknown when using the getrandom crate because even the solutions described above still don’t work. I have tried enabling the custom feature and registering a custom getrandom as described in the repo you shared and it still doesn’t work. I am trying to use candle-transformers crate to perform inference with huggingface models.

It has been a hell of a ride and it is so frustrating that none of the documented solutions work 🥲

---

<div class="post-metadata">

**Author:** ![baolongt](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@baolongt](https://forum.dfinity.org/u/baolongt)\
**Post date:** [June 15, 2025, 7:53am UTC](https://forum.dfinity.org/t/i-am-implementing-ibe-encryption-getting-error-while-using-system-api/34402/6 "2025-06-15T07:53:02Z")

</div>

> [@Issue about generate random string Panicked at 'could not initialize thread\_rng: getrandom: this target is not supported'](https://forum.dfinity.org/t/issue-about-generate-random-string-panicked-at-could-not-initialize-thread-rng-getrandom-this-target-is-not-supported/15198/8):
>
> This will return the same numbers every time. What you can do instead is seed an RNG of your choice with raw\_rand. Once created and stored in a static, this RNG can be used synchronously. For example: thread\_local! { static RNG: RefCell\<Option\<StdRng\>\> = RefCell::new(None); } #[init] fn init() { ic\_cdk:timer:set\_timer(Duration::ZERO, || ic\_cdk::spawn(async { let (seed,): ([u8; 32],) = ic\_cdk::call(Principal::management\_canister(), "raw\_rand", ()).await.unwrap(); RNG.wi…

I think this might help
