Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3491014
D5999.id20026.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
901 B
Referenced Files
None
Subscribers
None
D5999.id20026.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>,
+ string_to_be_signed: &str,
+) -> anyhow::Result<String> {
+ let mut signer = Signer::new(MessageDigest::sha256(), &private_key)?;
+ signer.update(string_to_be_signed.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
Thu, Dec 19, 6:16 PM (19 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678309
Default Alt Text
D5999.id20026.diff (901 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