Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3492564
D5999.id20255.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
873 B
Referenced Files
None
Subscribers
None
D5999.id20255.diff
View Options
diff --git a/native/native_rust_library/src/crypto_tools.rs b/native/native_rust_library/src/crypto_tools.rs
--- a/native/native_rust_library/src/crypto_tools.rs
+++ b/native/native_rust_library/src/crypto_tools.rs
@@ -1,5 +1,9 @@
use crate::ffi::DeviceType;
+use openssl::hash::MessageDigest;
+use openssl::pkey::PKey;
+use openssl::sign::Signer;
use rand::distributions::{Alphanumeric, DistString};
+
#[cfg(test)]
use regex::Regex;
@@ -33,6 +37,16 @@
Ok(format!("{}:{}", &prefix, &suffix))
}
+pub fn sign_string_with_private_key(
+ private_key: &PKey<openssl::pkey::Private>,
+ nonce: &str,
+) -> anyhow::Result<String> {
+ let mut signer = Signer::new(MessageDigest::sha256(), &private_key)?;
+ signer.update(nonce.as_bytes())?;
+ let signature = signer.sign_to_vec()?;
+ Ok(base64::encode(signature))
+}
+
#[cfg(test)]
mod tests {
use super::*;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 12:37 AM (20 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2676837
Default Alt Text
D5999.id20255.diff (873 B)
Attached To
Mode
D5999: [native/rust_library] Adding `sign_string_with_private_key` function to crypto tools
Attached
Detach File
Event Timeline
Log In to Comment