├── Android └── CryptoDemo │ ├── .idea │ ├── compiler.xml │ ├── gradle.xml │ ├── jarRepositories.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ └── vcs.xml │ ├── app │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── comtasoft │ │ │ └── cryptodemo │ │ │ └── ExampleInstrumentedTest.kt │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── comtasoft │ │ │ │ └── cryptodemo │ │ │ │ └── MainActivity.kt │ │ ├── jniLibs │ │ │ ├── arm64-v8a │ │ │ │ └── librust_crypto.so │ │ │ ├── armeabi-v7a │ │ │ │ └── librust_crypto.so │ │ │ └── x86_64 │ │ │ │ └── librust_crypto.so │ │ └── res │ │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── values-night │ │ │ └── themes.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ ├── styles.xml │ │ │ └── themes.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── comtasoft │ │ └── cryptodemo │ │ └── ExampleUnitTest.kt │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── Backend ├── cargo-config.toml ├── cargo-config.toml.template ├── cargo-config.toml.template.new.linux ├── cargo-config.toml.template.new.mac ├── create-ndk-build-info-linux.sh ├── create-ndk-build-info-mac.sh ├── create-ndk-standalone-ndk-r18.sh ├── create-ndk-standalone.sh ├── libs │ ├── rust-crypto-0.2.41 │ │ ├── CHANGELOG.md │ │ ├── Cargo.toml │ │ ├── LICENSE-APACHE │ │ ├── LICENSE-MIT │ │ ├── README.md │ │ ├── appveyor.yml │ │ ├── build.rs │ │ ├── examples │ │ │ └── symmetriccipher.rs │ │ └── src │ │ │ ├── aead.rs │ │ │ ├── aes.rs │ │ │ ├── aes_gcm.rs │ │ │ ├── aesni.rs │ │ │ ├── aesni_helpers.asm │ │ │ ├── aesni_helpers.c │ │ │ ├── aessafe.rs │ │ │ ├── api.rs │ │ │ ├── bcrypt.rs │ │ │ ├── bcrypt_pbkdf.rs │ │ │ ├── blake2b.rs │ │ │ ├── blake2s.rs │ │ │ ├── blockmodes.rs │ │ │ ├── blowfish.rs │ │ │ ├── buffer.rs │ │ │ ├── chacha20.rs │ │ │ ├── chacha20poly1305.rs │ │ │ ├── cryptoutil.rs │ │ │ ├── curve25519.rs │ │ │ ├── digest.rs │ │ │ ├── ed25519.rs │ │ │ ├── fortuna.rs │ │ │ ├── ghash.rs │ │ │ ├── hc128.rs │ │ │ ├── hkdf.rs │ │ │ ├── hmac.rs │ │ │ ├── lib.rs │ │ │ ├── mac.rs │ │ │ ├── md5.rs │ │ │ ├── pbkdf2.rs │ │ │ ├── poly1305.rs │ │ │ ├── rc4.rs │ │ │ ├── ripemd160.rs │ │ │ ├── salsa20.rs │ │ │ ├── scrypt.rs │ │ │ ├── sha1.rs │ │ │ ├── sha2.rs │ │ │ ├── sha3.rs │ │ │ ├── simd.rs │ │ │ ├── sosemanuk.rs │ │ │ ├── step_by.rs │ │ │ ├── symmetriccipher.rs │ │ │ ├── util.rs │ │ │ ├── util_helpers.asm │ │ │ ├── util_helpers.c │ │ │ └── whirlpool.rs │ └── rustc-serialize-0.3.24 │ │ ├── .cargo-ok │ │ ├── .travis.yml │ │ ├── Cargo.toml │ │ ├── LICENSE-APACHE │ │ ├── LICENSE-MIT │ │ ├── README.md │ │ ├── appveyor.yml │ │ ├── benches │ │ ├── base64.rs │ │ ├── hex.rs │ │ └── json.rs │ │ └── src │ │ ├── base64.rs │ │ ├── collection_impls.rs │ │ ├── hex.rs │ │ ├── json.rs │ │ ├── lib.rs │ │ └── serialize.rs └── rust_crypto │ ├── Cargo.toml │ └── src │ ├── lib.rs │ └── rust_crypto.h ├── Console └── cscrypto_2.1.2 │ ├── Cargo.toml │ ├── README.md │ └── src │ └── main.rs ├── Desktop ├── MainFrame.cpp ├── MainFrame.h ├── Makefile-linux ├── Makefile-mac ├── Makefile-win32 ├── Makefile-win64 ├── app.cpp ├── app.h └── res │ └── app.rc ├── README.md ├── Screenshoots ├── Android.png ├── Linux.png ├── WebAssembly.png ├── Win32.png ├── Windows-UWP.png ├── iOS.png └── macOS.png ├── UWP └── CryptoDemo │ ├── CryptoDemo.sln │ └── CryptoDemo │ ├── App.cpp │ ├── App.h │ ├── App.idl │ ├── App.xaml │ ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png │ ├── CryptoDemo.vcxproj │ ├── CryptoDemo.vcxproj.filters │ ├── CryptoDemo.vcxproj.user │ ├── CryptoDemo_TemporaryKey.pfx │ ├── MainPage.cpp │ ├── MainPage.h │ ├── MainPage.idl │ ├── MainPage.xaml │ ├── Package.appxmanifest │ ├── PropertySheet.props │ ├── build_rust-lib.cmd │ ├── packages.config │ ├── pch.cpp │ ├── pch.h │ └── readme.txt ├── WebAssembly └── crypto-demo │ ├── .appveyor.yml │ ├── .cargo-ok │ ├── .travis.yml │ ├── Cargo.toml │ ├── LICENSE_APACHE │ ├── LICENSE_MIT │ ├── README.md │ ├── package-lock.json │ ├── src │ ├── lib.rs │ └── utils.rs │ └── tests │ └── web.rs └── iOS └── CryptoDemo ├── ._CryptoDemo.xcodeproj ├── CryptoDemo.xcodeproj ├── ._project.xcworkspace ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings │ └── xcuserdata │ │ ├── owner.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── tungthanhnguyen.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ ├── WorkspaceSettings.xcsettings │ │ └── xcdebugger │ │ └── Expressions.xcexplist ├── xcshareddata │ └── xcschemes │ │ ├── Debug.xcscheme │ │ └── Release.xcscheme └── xcuserdata │ ├── owner.xcuserdatad │ └── xcschemes │ │ └── xcschememanagement.plist │ └── tungthanhnguyen.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── CryptoDemo.xcscheme │ └── xcschememanagement.plist ├── CryptoDemo ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CryptoDemo-Bridging-Header.h ├── Info.plist ├── RustCrypto.h ├── RustCrypto.m └── ViewController.swift └── OptimizationProfiles └── CryptoDemo.profdata /Android/CryptoDemo/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Android/CryptoDemo/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /Android/CryptoDemo/.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /Android/CryptoDemo/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /Android/CryptoDemo/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Android/CryptoDemo/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /Android/CryptoDemo/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Android/CryptoDemo/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdkVersion 30 8 | buildToolsVersion "30.0.3" 9 | 10 | defaultConfig { 11 | applicationId "com.comtasoft.cryptodemo" 12 | minSdkVersion 26 13 | targetSdkVersion 30 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | ndkVersion '23.0.7123448 rc1' 34 | } 35 | 36 | dependencies { 37 | 38 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 39 | implementation 'androidx.core:core-ktx:1.5.0' 40 | implementation 'androidx.appcompat:appcompat:1.3.0' 41 | implementation 'com.google.android.material:material:1.3.0' 42 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 43 | testImplementation 'junit:junit:4.13.2' 44 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 46 | } -------------------------------------------------------------------------------- /Android/CryptoDemo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/androidTest/java/com/comtasoft/cryptodemo/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.comtasoft.cryptodemo 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.comtasoft.cryptodemo", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/java/com/comtasoft/cryptodemo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.comtasoft.cryptodemo 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import android.widget.EditText 6 | import android.widget.TextView 7 | import androidx.appcompat.app.AppCompatActivity 8 | 9 | class MainActivity : AppCompatActivity() 10 | { 11 | private val pubKey = "ij2bL9WP9+R27/8VjjxVWoba4o3IbTpOme0o28Hjwic=" 12 | private val priKey = "E3B3Q3TglEQKg+w7CBkQ8XmrqemJ4fYGkTzWPSMUhW8=" 13 | 14 | init 15 | { 16 | System.loadLibrary("rust_crypto") 17 | } 18 | 19 | private external fun RustEncrypt(pubKey: String, message: String): String? 20 | private external fun RustDecrypt(priKey: String, message: String): String? 21 | 22 | private lateinit var edtMess: EditText 23 | private lateinit var lblEncryptedText: TextView 24 | private lateinit var lblDecryptedText: TextView 25 | 26 | override fun onCreate(savedInstanceState: Bundle?) 27 | { 28 | super.onCreate(savedInstanceState) 29 | setContentView(R.layout.activity_main) 30 | 31 | edtMess = findViewById(R.id.edtMess) 32 | lblEncryptedText = findViewById(R.id.lblEncryptedText) 33 | lblDecryptedText = findViewById(R.id.lblDecryptedText) 34 | } 35 | 36 | fun onAction(view: View) 37 | { 38 | val sMess = edtMess.text.toString().trim() 39 | if (sMess.isNotEmpty()) 40 | { 41 | val encMess = RustEncrypt(pubKey, sMess) 42 | val decMess = RustDecrypt(priKey, encMess.toString()) 43 | 44 | lblEncryptedText.text = encMess 45 | lblDecryptedText.text = decMess 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/jniLibs/arm64-v8a/librust_crypto.so: -------------------------------------------------------------------------------- 1 | ./../../../../../../../Backend/rust_crypto/target/aarch64-linux-android/release/librust_crypto.so -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/jniLibs/armeabi-v7a/librust_crypto.so: -------------------------------------------------------------------------------- 1 | ./../../../../../../../Backend/rust_crypto/target/armv7-linux-androideabi/release/librust_crypto.so -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/jniLibs/x86_64/librust_crypto.so: -------------------------------------------------------------------------------- 1 | ./../../../../../../../Backend/rust_crypto/target/x86_64-linux-android/release/librust_crypto.so -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /Android/CryptoDemo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 32 | 33 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /UWP/CryptoDemo/CryptoDemo/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 7 | 8 | 9 | CryptoDemo 10 | tungthanhnguyen 11 | Assets\StoreLogo.png 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /UWP/CryptoDemo/CryptoDemo/PropertySheet.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /UWP/CryptoDemo/CryptoDemo/build_rust-lib.cmd: -------------------------------------------------------------------------------- 1 | rem @echo off 2 | 3 | rem i686 x86_64 aarch64 4 | SET BUILD_ARCH=%1 5 | 6 | rem debug release 7 | SET BUILD_TYPE=%2 8 | 9 | SET LIB_RUST_NAME=rust_crypto 10 | SET RUST_TARGET=%BUILD_ARCH%-pc-windows-msvc 11 | SET CORELIB_DIR=..\..\..\Backend\%LIB_RUST_NAME% 12 | SET CARGO_COMMAND=%USERPROFILE%\.cargo\bin\cargo.exe 13 | 14 | IF %BUILD_TYPE% == debug ( 15 | %CARGO_COMMAND% build --target %RUST_TARGET% --manifest-path %CORELIB_DIR%\Cargo.toml 16 | ) ELSE ( 17 | %CARGO_COMMAND% build --target %RUST_TARGET% --%BUILD_TYPE% --manifest-path %CORELIB_DIR%\Cargo.toml 18 | ) 19 | 20 | copy %CORELIB_DIR%\target\%RUST_TARGET%\%BUILD_TYPE%\%LIB_RUST_NAME%.lib %CORELIB_DIR%\target -------------------------------------------------------------------------------- /UWP/CryptoDemo/CryptoDemo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /UWP/CryptoDemo/CryptoDemo/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /UWP/CryptoDemo/CryptoDemo/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /UWP/CryptoDemo/CryptoDemo/readme.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | C++/WinRT CryptoDemo Project Overview 3 | ======================================================================== 4 | 5 | This project demonstrates how to get started writing XAML apps directly 6 | with standard C++, using the C++/WinRT SDK component and XAML compiler 7 | support to generate implementation headers from interface (IDL) files. 8 | These headers can then be used to implement the local Windows Runtime 9 | classes referenced in the app's XAML pages. 10 | 11 | Steps: 12 | 1. Create an interface (IDL) file to define any local Windows Runtime 13 | classes referenced in the app's XAML pages. 14 | 2. Build the project once to generate implementation templates under 15 | the "Generated Files" folder, as well as skeleton class definitions 16 | under "Generated Files\sources". 17 | 3. Use the skeleton class definitions for reference to implement your 18 | Windows Runtime classes. 19 | 20 | ======================================================================== 21 | Learn more about C++/WinRT here: 22 | http://aka.ms/cppwinrt/ 23 | ======================================================================== 24 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/.appveyor.yml: -------------------------------------------------------------------------------- 1 | install: 2 | - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe 3 | - if not defined RUSTFLAGS rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly 4 | - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin 5 | - rustc -V 6 | - cargo -V 7 | 8 | build: false 9 | 10 | test_script: 11 | - cargo test --locked 12 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/.cargo-ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/WebAssembly/crypto-demo/.cargo-ok -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | sudo: false 3 | 4 | cache: cargo 5 | 6 | matrix: 7 | include: 8 | 9 | # Builds with wasm-pack. 10 | - rust: beta 11 | env: RUST_BACKTRACE=1 12 | addons: 13 | firefox: latest 14 | chrome: stable 15 | before_script: 16 | - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) 17 | - (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) 18 | - cargo install-update -a 19 | - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f 20 | script: 21 | - cargo generate --git . --name testing 22 | # Having a broken Cargo.toml (in that it has curlies in fields) anywhere 23 | # in any of our parent dirs is problematic. 24 | - mv Cargo.toml Cargo.toml.tmpl 25 | - cd testing 26 | - wasm-pack build 27 | - wasm-pack test --chrome --firefox --headless 28 | 29 | # Builds on nightly. 30 | - rust: nightly 31 | env: RUST_BACKTRACE=1 32 | before_script: 33 | - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) 34 | - (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) 35 | - cargo install-update -a 36 | - rustup target add wasm32-unknown-unknown 37 | script: 38 | - cargo generate --git . --name testing 39 | - mv Cargo.toml Cargo.toml.tmpl 40 | - cd testing 41 | - cargo check 42 | - cargo check --target wasm32-unknown-unknown 43 | - cargo check --no-default-features 44 | - cargo check --target wasm32-unknown-unknown --no-default-features 45 | - cargo check --no-default-features --features console_error_panic_hook 46 | - cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook 47 | - cargo check --no-default-features --features "console_error_panic_hook wee_alloc" 48 | - cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc" 49 | 50 | # Builds on beta. 51 | - rust: beta 52 | env: RUST_BACKTRACE=1 53 | before_script: 54 | - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) 55 | - (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) 56 | - cargo install-update -a 57 | - rustup target add wasm32-unknown-unknown 58 | script: 59 | - cargo generate --git . --name testing 60 | - mv Cargo.toml Cargo.toml.tmpl 61 | - cd testing 62 | - cargo check 63 | - cargo check --target wasm32-unknown-unknown 64 | - cargo check --no-default-features 65 | - cargo check --target wasm32-unknown-unknown --no-default-features 66 | - cargo check --no-default-features --features console_error_panic_hook 67 | - cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook 68 | # Note: no enabling the `wee_alloc` feature here because it requires 69 | # nightly for now. 70 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "crypto-demo" 3 | version = "0.1.0" 4 | authors = ["tungthanhnguyen"] 5 | edition = "2018" 6 | 7 | [lib] 8 | crate-type = ["cdylib", "rlib"] 9 | 10 | [features] 11 | default = ["console_error_panic_hook"] 12 | 13 | [build-dependencies] 14 | rust_crypto = { version = "0.1.3", path = "../../Backend/rust_crypto" } 15 | 16 | [dependencies] 17 | wasm-bindgen = "0.2.74" 18 | rust_crypto = { version = "0.1.3", path = "../../Backend/rust_crypto" } 19 | rustc-serialize = { version = "0.3.24", path = "../../Backend/libs/rustc-serialize-0.3.24" } 20 | 21 | # The `console_error_panic_hook` crate provides better debugging of panics by 22 | # logging them with `console.error`. This is great for development, but requires 23 | # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for 24 | # code size when deploying. 25 | console_error_panic_hook = { version = "0.1.6", optional = true } 26 | 27 | # `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size 28 | # compared to the default allocator's ~10K. It is slower than the default 29 | # allocator, however. 30 | # 31 | # Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now. 32 | wee_alloc = { version = "0.4.5", optional = true } 33 | 34 | # [dependencies.wasm-opt] 35 | # wasm-opt = false 36 | 37 | getrandom = { version = "0.2", features = ["js"] } 38 | 39 | [dependencies.web-sys] 40 | version = "0.3.51" 41 | features = ["console"] 42 | 43 | [dev-dependencies] 44 | wasm-bindgen-test = "0.3.24" 45 | 46 | [profile.release] 47 | # Tell `rustc` to optimize for small code size. 48 | opt-level = "s" 49 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 tungthanhnguyen 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |

wasm-pack-template

4 | 5 | A template for kick starting a Rust and WebAssembly project using wasm-pack. 6 | 7 |

8 | Build Status 9 |

10 | 11 |

12 | Tutorial 13 | | 14 | Chat 15 |

16 | 17 | Built with 🦀🕸 by The Rust and WebAssembly Working Group 18 |
19 | 20 | ## About 21 | 22 | [**📚 Read this template tutorial! 📚**][template-docs] 23 | 24 | This template is designed for compiling Rust libraries into WebAssembly and 25 | publishing the resulting package to NPM. 26 | 27 | Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other 28 | templates and usages of `wasm-pack`. 29 | 30 | [tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html 31 | [template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html 32 | 33 | ## 🚴 Usage 34 | 35 | ### 🐑 Use `cargo generate` to Clone this Template 36 | 37 | [Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate) 38 | 39 | ``` 40 | cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project 41 | cd my-project 42 | ``` 43 | 44 | ### 🛠️ Build with `wasm-pack build` 45 | 46 | ``` 47 | wasm-pack build 48 | ``` 49 | 50 | ### 🔬 Test in Headless Browsers with `wasm-pack test` 51 | 52 | ``` 53 | wasm-pack test --headless --firefox 54 | ``` 55 | 56 | ### 🎁 Publish to NPM with `wasm-pack publish` 57 | 58 | ``` 59 | wasm-pack publish 60 | ``` 61 | 62 | ## 🔋 Batteries Included 63 | 64 | * [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating 65 | between WebAssembly and JavaScript. 66 | * [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook) 67 | for logging panic messages to the developer console. 68 | * [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized 69 | for small code size. 70 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crypto-demo", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": {} 6 | } 7 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_crypto; 2 | extern crate rustc_serialize; 3 | extern crate web_sys; 4 | 5 | mod utils; 6 | 7 | use std::vec::Vec; 8 | 9 | use wasm_bindgen::prelude::*; 10 | 11 | use rustc_serialize::base64::{FromBase64, ToBase64, STANDARD}; 12 | 13 | use rust_crypto::{encrypt_buf, decrypt_buf}; 14 | 15 | // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global 16 | // allocator. 17 | #[cfg(feature = "wee_alloc")] 18 | #[global_allocator] 19 | static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; 20 | 21 | // A macro to provide `println!(..)`-style syntax for `console.log` logging. 22 | macro_rules! log 23 | { 24 | ( $( $t:tt )* ) => 25 | { 26 | web_sys::console::log_1(&format!( $( $t )* ).into()); 27 | } 28 | } 29 | 30 | #[wasm_bindgen(js_name = "encrypt")] 31 | pub fn wasm_encrypt(pub_key: String, msg: String) -> String 32 | { 33 | // utils::set_panic_hook(); 34 | 35 | let mut arr = [0u8; 32]; // temp buffer 36 | let public_key: &[u8; 32] = match pub_key.trim().from_base64() 37 | { 38 | Ok(m) => 39 | { 40 | if m.len() != 32 41 | { 42 | // let e_str = format!("Public key size is wrong"); 43 | // log!("{}", e_str); 44 | return String::new() 45 | } 46 | arr.copy_from_slice(&m); 47 | &arr 48 | }, 49 | Err(why) => 50 | { 51 | // let e_str = format!("Public key is wrong\n For reason: {}", why); 52 | // log!("{}", e_str); 53 | return String::new() 54 | } 55 | }; 56 | 57 | let enc_dat: Vec = match encrypt_buf(&public_key, msg.as_bytes()) 58 | { 59 | Ok(d) => d, 60 | Err(_) => 61 | { 62 | // let e_str = format!("Couldn't encrypt a buffer"); 63 | // log!("{}", e_str); 64 | return String::new() 65 | } 66 | }; 67 | 68 | String::from(enc_dat.as_slice().to_base64(STANDARD)) 69 | } 70 | 71 | #[wasm_bindgen(js_name = "decrypt")] 72 | pub fn wasm_decrypt(pri_key: String, msg: String) -> String 73 | { 74 | // utils::set_panic_hook(); 75 | 76 | let mut arr = [0u8; 32]; // temp buff 77 | let private_key: &[u8; 32] = match pri_key.trim().from_base64() 78 | { 79 | Ok(m) => 80 | { 81 | if m.len() != 32 82 | { 83 | // let e_str = format!("Private key size is wrong"); 84 | // log!("{}", e_str); 85 | return String::new() 86 | } 87 | arr.copy_from_slice(&m); 88 | &arr 89 | }, 90 | Err(why) => 91 | { 92 | // let e_str = format!("Private key is wrong\n For reason: {}", why); 93 | // log!("{}", e_str); 94 | return String::new() 95 | } 96 | }; 97 | 98 | let recv_msg: Vec = match msg.as_bytes().from_base64() 99 | { 100 | Ok(r) => r, 101 | Err(_) => 102 | { 103 | // let e_str = format!("Invalid Base64 string"); 104 | // log!("{}", e_str); 105 | return String::new() 106 | } 107 | }; 108 | 109 | let dec_dat: Vec = match decrypt_buf(&private_key, &recv_msg) 110 | { 111 | Ok(d) => d, 112 | Err(_) => 113 | { 114 | // let e_str = format!("Couldn't decrypt data"); 115 | // log!("{}", e_str); 116 | return String::new() 117 | } 118 | }; 119 | 120 | String::from_utf8(dec_dat).unwrap() 121 | } 122 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/src/utils.rs: -------------------------------------------------------------------------------- 1 | pub fn set_panic_hook() { 2 | // When the `console_error_panic_hook` feature is enabled, we can call the 3 | // `set_panic_hook` function at least once during initialization, and then 4 | // we will get better error messages if our code ever panics. 5 | // 6 | // For more details see 7 | // https://github.com/rustwasm/console_error_panic_hook#readme 8 | #[cfg(feature = "console_error_panic_hook")] 9 | console_error_panic_hook::set_once(); 10 | } 11 | -------------------------------------------------------------------------------- /WebAssembly/crypto-demo/tests/web.rs: -------------------------------------------------------------------------------- 1 | //! Test suite for the Web and headless browsers. 2 | 3 | #![cfg(target_arch = "wasm32")] 4 | 5 | extern crate wasm_bindgen_test; 6 | use wasm_bindgen_test::*; 7 | 8 | wasm_bindgen_test_configure!(run_in_browser); 9 | 10 | #[wasm_bindgen_test] 11 | fn pass() { 12 | assert_eq!(1 + 1, 2); 13 | } 14 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/._CryptoDemo.xcodeproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/._CryptoDemo.xcodeproj -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/._project.xcworkspace: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/CryptoDemo.xcodeproj/._project.xcworkspace -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/owner.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/owner.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | EnabledFullIndexStoreVisibility 12 | 13 | IssueFilterStyle 14 | ShowActiveSchemeOnly 15 | LiveSourceIssuesEnabled 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/xcdebugger/Expressions.xcexplist: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | 23 | 24 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/xcshareddata/xcschemes/Release.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 48 | 50 | 56 | 57 | 58 | 59 | 65 | 67 | 73 | 74 | 75 | 76 | 78 | 79 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/owner.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Debug.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 1 11 | 12 | Release.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 8FA604D51EF5204700D6B7EF 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/tungthanhnguyen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/tungthanhnguyen.xcuserdatad/xcschemes/CryptoDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/tungthanhnguyen.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CryptoDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | Release.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 8FA604D51EF5204700D6B7EF 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CryptoDemo 4 | // 5 | // Created by Tung Thanh Nguyen on 6/17/17. 6 | // Copyright © 2017 Comtasoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/CryptoDemo-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | // 6 | // CryptoDemo-Bridging-Header.h 7 | // CryptoDemo 8 | // 9 | // Created by Tung Thanh Nguyen on 6/17/17. 10 | // Copyright © 2017 Comtasoft. All rights reserved. 11 | // 12 | 13 | #ifndef CryptoDemo_Bridging_Header_h 14 | #define CryptoDemo_Bridging_Header_h 15 | 16 | #import 17 | 18 | #include "RustCrypto.h" 19 | 20 | #endif /* CryptoDemo_Bridging_Header_h */ 21 | 22 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/RustCrypto.h: -------------------------------------------------------------------------------- 1 | // 2 | // RustCrypto.h 3 | // CryptoDemo 4 | // 5 | // Created by Tung Thanh Nguyen on 6/17/17. 6 | // Copyright © 2017 Comtasoft. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #include "rust_crypto.h" 12 | 13 | @interface RustCrypto : NSObject 14 | 15 | - (instancetype) init; 16 | 17 | - (NSString*) encrypt:(NSString*) pubKey rawMessage:(NSString*) message; 18 | - (NSString*) decrypt:(NSString*) priKey encryptedMessage:(NSString*) message; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/RustCrypto.m: -------------------------------------------------------------------------------- 1 | // 2 | // RustCrypto.m 3 | // CryptoDemo 4 | // 5 | // Created by Tung Thanh Nguyen on 6/17/17. 6 | // Copyright © 2017 Comtasoft. All rights reserved. 7 | // 8 | 9 | #import "RustCrypto.h" 10 | 11 | @implementation RustCrypto 12 | 13 | - (instancetype) init 14 | { 15 | self = [super init]; 16 | return self; 17 | } 18 | 19 | - (NSString*) encrypt:(NSString*) pubKey rawMessage:(NSString*) message 20 | { 21 | const char* result = (const char *) rust_encrypt([pubKey UTF8String], [message UTF8String]); 22 | return [[NSString alloc] initWithCString:result encoding:NSUTF8StringEncoding]; 23 | } 24 | 25 | - (NSString*) decrypt:(NSString*) priKey encryptedMessage:(NSString*) message 26 | { 27 | const char* result = rust_decrypt([priKey UTF8String], [message UTF8String]); 28 | return [[NSString alloc] initWithCString:result encoding:NSUTF8StringEncoding]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/CryptoDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CryptoDemo 4 | // 5 | // Created by Tung Thanh Nguyen on 6/17/17. 6 | // Copyright © 2017 Comtasoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController 12 | { 13 | @IBOutlet var message: UITextField! 14 | @IBOutlet var lblEncryptedText: UILabel! 15 | @IBOutlet var lblDecryptedText: UILabel! 16 | 17 | let crypto = RustCrypto()! 18 | 19 | let pubKey = "ij2bL9WP9+R27/8VjjxVWoba4o3IbTpOme0o28Hjwic=" 20 | let priKey = "E3B3Q3TglEQKg+w7CBkQ8XmrqemJ4fYGkTzWPSMUhW8=" 21 | 22 | override func viewDidLoad() 23 | { 24 | super.viewDidLoad() 25 | // Do any additional setup after loading the view, typically from a nib. 26 | } 27 | 28 | override func didReceiveMemoryWarning() 29 | { 30 | super.didReceiveMemoryWarning() 31 | // Dispose of any resources that can be recreated. 32 | } 33 | 34 | @IBAction func action(_ sender: UIButton) 35 | { 36 | if !(message.text?.isEmpty)! && !(message.text?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty)! 37 | { 38 | let c = crypto.encrypt(pubKey, rawMessage: message.text?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)) 39 | let d = crypto.decrypt(priKey, encryptedMessage: c) 40 | 41 | lblEncryptedText.text = c 42 | lblDecryptedText.text = d 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /iOS/CryptoDemo/OptimizationProfiles/CryptoDemo.profdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/OptimizationProfiles/CryptoDemo.profdata --------------------------------------------------------------------------------