├── .gitignore ├── .idea ├── libraries │ ├── Dart_SDK.xml │ └── Flutter_for_Android.xml ├── modules.xml ├── runConfigurations │ └── main_dart.xml └── workspace.xml ├── .metadata ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── crptodemo │ │ │ └── MainActivity.java │ │ └── res │ │ ├── drawable │ │ └── launch_background.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── crpto_demo.iml ├── crpto_demo_android.iml ├── images └── qq155353383.jpg ├── ios ├── .gitignore ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ └── Release.xcconfig ├── Podfile ├── Podfile.lock ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Runner │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-1024x1024@1x.png │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ └── Icon-App-83.5x83.5@2x.png │ └── LaunchImage.imageset │ │ ├── Contents.json │ │ ├── LaunchImage.png │ │ ├── LaunchImage@2x.png │ │ ├── LaunchImage@3x.png │ │ └── README.md │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── main.m ├── lib ├── crypto │ ├── aes_pkcs │ │ ├── base_padding.dart │ │ ├── padded_block_cipher.dart │ │ ├── pkcs7.dart │ │ └── ufixnum.dart │ ├── bbs │ │ ├── bbs.dart │ │ └── src │ │ │ ├── bbs_base.dart │ │ │ ├── bbs_blum.dart │ │ │ └── bbs_primes.dart │ ├── crypto_aes.dart │ ├── crypto_provider.dart │ ├── crypto_rsa.dart │ ├── des │ │ ├── src │ │ │ ├── block_cipher.dart │ │ │ ├── constants.dart │ │ │ ├── des.dart │ │ │ ├── engine.dart │ │ │ ├── tripledes.dart │ │ │ └── utils.dart │ │ └── tripledes.dart │ ├── rsa │ │ ├── rsa.dart │ │ ├── rsa_block.dart │ │ ├── rsa_key_formatter.dart │ │ └── src │ │ │ ├── rsa_hashing.dart │ │ │ ├── rsa_key.dart │ │ │ ├── rsa_keypair.dart │ │ │ ├── rsa_math.dart │ │ │ ├── rsa_padding.dart │ │ │ ├── rsa_pkcs1.dart │ │ │ └── rsa_tools.dart │ └── rsa_pkcs │ │ ├── rsa_pkcs.dart │ │ └── src │ │ └── parser.dart ├── main.dart └── string_utils.dart ├── pubspec.yaml └── test └── widget_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | .pub/ 7 | build/ 8 | # If you're building an application, you may want to check-in your pubspec.lock 9 | pubspec.lock 10 | 11 | # Directory created by dartdoc 12 | # If you don't generate documentation locally you can remove this line. 13 | doc/api/ 14 | -------------------------------------------------------------------------------- /.idea/libraries/Dart_SDK.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/Flutter_for_Android.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations/main_dart.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 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 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: c7ea3ca377e909469c68f2ab878a5bc53d3cf66b 8 | channel: beta 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Flutter", 9 | "request": "launch", 10 | "type": "dart" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Created by dyf on 2018/8/31. 2 | Copyright (c) 2018 dyf. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject 10 | to the following conditions: 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 15 | WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR 18 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR 23 | IN CONNECTION WITH THE SOFTWARE OR 24 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 如果能帮助到你,就请你给一颗[star](https://github.com/chenxing640/dart_crypto),谢谢!(If this can help you, please give it a [star](https://github.com/chenxing640/dart_crypto), thanks!) 2 | 3 | [![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE)  4 | [![Support](https://img.shields.io/badge/support-iOS%20|%20Android-blue.svg?style=flat)](https://flutterchina.club)  5 | 6 | ## dart_crypto 7 | 8 | 集成了Base64, 32/16 Bits MD5, AES, RSA等算法(This integrates Base64, 32/16 Bits MD5, AES and RSA algorithms.)。 9 | 10 | ## Group(ID:155353383) 11 | 12 |
13 |   14 |
15 | 16 | ## Recommendation 17 | 18 | * [Grab ethtoken info](https://github.com/chenxing640/grab_ethtoken_info) 19 | 20 | ## Getting Started 21 | 22 | For help getting started with Flutter, view the online
23 | 24 | * [Flutter Hub](https://github.com/chenxing640/Awesome/blob/master/Flutter.md) 25 | 26 | ## Usage 27 | 28 | ### Plain Text 29 | 30 | ```dart 31 | final plainText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit ........。本文基本上是将dart官网部分内容进行翻译,没兴趣的请出门左转至Dart的官网,有兴趣的同志请继续阅读本文。Flutter教程在这里通常,映射是一个有键和值的对象。 键和值都可以是任何类型的对象。 每个键只出现一次,但您可以多次使用相同的值。Dart的Map支持由映射文字和Map。int和double都是num的子类型。 num类型包括基本运算符,如+, - ,/和*,也是你可以找到abs(),ceil()和floor()以及其他方法的地方。 (按位运算符,如>>,在int类中有定义。)如果num及其子类没有您要想要内容,那dart:math库可能有您想要的。Dart字符串是一系列UTF-16代码单元。 您可以使用单引号或双引号来创建字符串:您可以使用{expression}将表达式的值放在字符串中。如果表达式是标识符,则可以跳过{}。 要获取对应于对象的字符串,Dart调用对象的toString()方法。为了表示布尔值,Dart有一个名为bool的类型。 只有两个对象具有bool类型:true和false,它们都是编译时常量。Dart的类型安全意味着您不能使用if(nonbooleanValue)或assert(nonbooleanValue)等代码。 相反,明确检查值,如下所示:也许几乎每种编程语言中最常见的集合是数组或有序的对象组。 在Dart中,数组是List对象,因此大多数人只是将它们称为列表。Dart列表文字看起来像JavaScript数组文字。 这是一个简单的Dart List:"; 32 | ``` 33 | 34 | ### Base64 35 | 36 | ```dart 37 | try { 38 | // Base64 - Encode 39 | final base64Encoded = crypto.DYFCryptoProvider.yf_base64Encode(plainText); 40 | print("[Base64] encode: " + base64Encoded); 41 | 42 | // Base64 - Dncode 43 | final base64Decoded = crypto.DYFCryptoProvider.yf_base64Decode(base64Encoded); 44 | print("[Base64] decode: " + base64Decoded); 45 | } catch (e) { 46 | print("e: $e"); 47 | } 48 | ``` 49 | 50 | ### MD5 51 | 52 | ```dart 53 | try { 54 | // MD5 - 32 Bits Encode 55 | final md5Hash = crypto.DYFCryptoProvider.md5Encode(plainText); 56 | print("[MD5] Hash: " + md5Hash); 57 | 58 | // MD5 - 16 Bits Encode 59 | final md5b16hash = crypto.DYFCryptoProvider.bit16md5Enconde(plainText); 60 | print("[MD5] 16 Bits Hash: " + md5b16hash); 61 | } catch (e) { 62 | print("e: $e"); 63 | } 64 | ``` 65 | 66 | ### AES 67 | 68 | ```dart 69 | try { 70 | // AES Key 71 | // final aesKey = "smMQI8dMK2nOMUR0TdpBYQUnLpbW8kjHrdy86WtU6eB1Ff6mYveYzezopmbjwBZEjPQmg"; 72 | final aesKey = "smMQI8dMK2"; 73 | print("[AES] key: " + aesKey); 74 | 75 | // AES - Encrypt 76 | String aesEncryptedText = crypto.DYFCryptoProvider.aesEncrypt(plainText, aesKey); 77 | print("[AES] encryptedText: " + aesEncryptedText); 78 | 79 | // AES - Decrypt 80 | String aesDecryptedText = crypto.DYFCryptoProvider.aesDecrypt(aesEncryptedText, aesKey); 81 | print("[AES] decryptedText: " + aesDecryptedText); 82 | } catch (e) { 83 | print("e: $e"); 84 | } 85 | ``` 86 | 87 | ### RSA 88 | 89 | ``` 90 | // 公钥 91 | final publicKey = 92 | """MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmPW2SwJFldGVB1SM82VYvSZYR 93 | F1H5DREUiDK2SLnksxHAV/roC1uB44a4siUehJ9AKeV/g58pVrjhX3eSiBh9Khom 94 | /S2hEWF2n/6+lqqiwQi1W5rjl86v+dI2F6NgbPFpfesrRjWD9uskT2VX/ZJuMRLz 95 | 8VPIyQOM9TW3PkMYBQIDAQAB"""; 96 | 97 | // 私钥 (pkcs8) 98 | final privateKey = 99 | """MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKY9bZLAkWV0ZUHV 100 | IzzZVi9JlhEXUfkNERSIMrZIueSzEcBX+ugLW4HjhriyJR6En0Ap5X+DnylWuOFf 101 | d5KIGH0qGib9LaERYXaf/r6WqqLBCLVbmuOXzq/50jYXo2Bs8Wl96ytGNYP26yRP 102 | ZVf9km4xEvPxU8jJA4z1Nbc+QxgFAgMBAAECgYArZVW5PXO3HE9ihBUSyVlqNrdp 103 | 9sB7VyHiTjuOwiVkwiocH9trv6s/mPmONVLjSJOZ2FYEl4Nw8yaIDrfUFJrvhdbh 104 | HJnwkO27Wo5jEfm2qGCwgQNtUACoIH637LXfP81v5I7eZtEa7kfO8Axpp3czvO1H 105 | dIAlOI8rU4jb3fB1cQJBANLgfHd/CDro1gtvTrUeTw/lqsKVScGiHn+pmT+THed6 106 | ftJ2MAJVcL/0H8+fFN5mRypCL7LQyPO48dTmfY9PbocCQQDJz8xZGq2BNAd3gSrN 107 | i3q++SEyjRPzDfr8AGJBJF8qtslcSYrVB/jjPx/qNNlMxOoXnpozBojzVTO3UirM 108 | J/wTAkEAzb930YOhPREGHnwImFCtJT6ZYGcWYpXSGg8Y1d2tlLeA28myx+QjMTZ4 109 | fzOgwemaz9FqBpcNKjctxOLqaRRAKwJAXPZwznbgh8zcx6rjea2PjFscdLnR/7tn 110 | 6x+OIy3K/NUYan+iCUHT33JblDpmAtwObXTs2SZgfZ645PBfsI2WqwJAGJxnG8+w 111 | iCnzN0CIZvG96tfOZmz0lkM4NSHDwdCSbagJlZccOtodpn00Dzy+l0t+oFe0Xm3R 112 | A0WkPzQX/seO0Q=="""; 113 | ``` 114 | 115 | ```dart 116 | try { 117 | // RSA - Encrypt 118 | String rsaEncryptedText = crypto.DYFCryptoProvider.rsaEncrypt(plainText, publicKey); 119 | print("[rsa] encryptedText: " + rsaEncryptedText); 120 | 121 | // RSA - Decrypt 122 | String rsaDecryptedText = crypto.DYFCryptoProvider.rsaDecrypt(rsaEncryptedText, privateKey); 123 | print("[rsa] decryptedText: " + rsaDecryptedText); 124 | 125 | // RSA - Sign 126 | String signature = crypto.DYFCryptoProvider.rsaSign(plainText, privateKey); 127 | print("[rsa] signature: " + signature); 128 | 129 | // RSA - Verify 130 | bool ret = crypto.DYFCryptoProvider.rsaVerify(signature, plainText, publicKey); 131 | print("[rsa] signature verification: " + ret.toString()); 132 | } catch (e) { 133 | print("e: $e"); 134 | } 135 | ``` 136 | 137 | ## Feedback is welcome 138 | 139 | If you notice any issue, please create an issue. I will be happy to help you. 140 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.class 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | GeneratedPluginRegistrant.java 11 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | apply plugin: 'com.android.application' 15 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 16 | 17 | android { 18 | compileSdkVersion 27 19 | 20 | lintOptions { 21 | disable 'InvalidPackage' 22 | } 23 | 24 | defaultConfig { 25 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 26 | applicationId "com.example.crptodemo" 27 | minSdkVersion 16 28 | targetSdkVersion 27 29 | versionCode 1 30 | versionName "1.0" 31 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 32 | } 33 | 34 | buildTypes { 35 | release { 36 | // TODO: Add your own signing config for the release build. 37 | // Signing with the debug keys for now, so `flutter run --release` works. 38 | signingConfig signingConfigs.debug 39 | } 40 | } 41 | } 42 | 43 | flutter { 44 | source '../..' 45 | } 46 | 47 | dependencies { 48 | testImplementation 'junit:junit:4.12' 49 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 50 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 51 | } 52 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 15 | 19 | 26 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/example/crptodemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.crptodemo; 2 | 3 | import android.os.Bundle; 4 | import io.flutter.app.FlutterActivity; 5 | import io.flutter.plugins.GeneratedPluginRegistrant; 6 | 7 | public class MainActivity extends FlutterActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | GeneratedPluginRegistrant.registerWith(this); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.0.1' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | google() 15 | jcenter() 16 | } 17 | } 18 | 19 | rootProject.buildDir = '../build' 20 | subprojects { 21 | project.buildDir = "${rootProject.buildDir}/${project.name}" 22 | } 23 | subprojects { 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 4 | 5 | def plugins = new Properties() 6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') 7 | if (pluginsFile.exists()) { 8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } 9 | } 10 | 11 | plugins.each { name, path -> 12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() 13 | include ":$name" 14 | project(":$name").projectDir = pluginDirectory 15 | } 16 | -------------------------------------------------------------------------------- /crpto_demo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /crpto_demo_android.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /images/qq155353383.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/images/qq155353383.jpg -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vagrant/ 3 | .sconsign.dblite 4 | .svn/ 5 | 6 | .DS_Store 7 | *.swp 8 | profile 9 | 10 | DerivedData/ 11 | build/ 12 | GeneratedPluginRegistrant.h 13 | GeneratedPluginRegistrant.m 14 | 15 | .generated/ 16 | 17 | *.pbxuser 18 | *.mode1v3 19 | *.mode2v3 20 | *.perspectivev3 21 | 22 | !default.pbxuser 23 | !default.mode1v3 24 | !default.mode2v3 25 | !default.perspectivev3 26 | 27 | xcuserdata 28 | 29 | *.moved-aside 30 | 31 | *.pyc 32 | *sync/ 33 | Icon? 34 | .tags* 35 | 36 | /Flutter/app.flx 37 | /Flutter/app.zip 38 | /Flutter/flutter_assets/ 39 | /Flutter/App.framework 40 | /Flutter/Flutter.framework 41 | /Flutter/Generated.xcconfig 42 | /ServiceDefinitions.json 43 | 44 | Pods/ 45 | .symlinks/ 46 | -------------------------------------------------------------------------------- /ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | def parse_KV_file(file, separator='=') 8 | file_abs_path = File.expand_path(file) 9 | if !File.exists? file_abs_path 10 | return []; 11 | end 12 | pods_ary = [] 13 | skip_line_start_symbols = ["#", "/"] 14 | File.foreach(file_abs_path) { |line| 15 | next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } 16 | plugin = line.split(pattern=separator) 17 | if plugin.length == 2 18 | podname = plugin[0].strip() 19 | path = plugin[1].strip() 20 | podpath = File.expand_path("#{path}", file_abs_path) 21 | pods_ary.push({:name => podname, :path => podpath}); 22 | else 23 | puts "Invalid plugin specification: #{line}" 24 | end 25 | } 26 | return pods_ary 27 | end 28 | 29 | target 'Runner' do 30 | # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock 31 | # referring to absolute paths on developers' machines. 32 | system('rm -rf .symlinks') 33 | system('mkdir -p .symlinks/plugins') 34 | 35 | # Flutter Pods 36 | generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig') 37 | if generated_xcode_build_settings.empty? 38 | puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first." 39 | end 40 | generated_xcode_build_settings.map { |p| 41 | if p[:name] == 'FLUTTER_FRAMEWORK_DIR' 42 | symlink = File.join('.symlinks', 'flutter') 43 | File.symlink(File.dirname(p[:path]), symlink) 44 | pod 'Flutter', :path => File.join(symlink, File.basename(p[:path])) 45 | end 46 | } 47 | 48 | # Plugin Pods 49 | plugin_pods = parse_KV_file('../.flutter-plugins') 50 | plugin_pods.map { |p| 51 | symlink = File.join('.symlinks', 'plugins', p[:name]) 52 | File.symlink(p[:path], symlink) 53 | pod p[:name], :path => File.join(symlink, 'ios') 54 | } 55 | end 56 | 57 | post_install do |installer| 58 | installer.pods_project.targets.each do |target| 59 | target.build_configurations.each do |config| 60 | config.build_settings['ENABLE_BITCODE'] = 'NO' 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | 4 | DEPENDENCIES: 5 | - Flutter (from `.symlinks/flutter/ios`) 6 | 7 | EXTERNAL SOURCES: 8 | Flutter: 9 | :path: ".symlinks/flutter/ios" 10 | 11 | SPEC CHECKSUMS: 12 | Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296 13 | 14 | PODFILE CHECKSUM: 1e5af4103afd21ca5ead147d7b81d06f494f51a2 15 | 16 | COCOAPODS: 1.5.3 17 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 12 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 13 | 8418942A7DD0BF83080B943F /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BCB02E1CBE594F0CD1623AD /* libPods-Runner.a */; }; 14 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 15 | 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; }; 16 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 17 | 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 18 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 19 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 20 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 25 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 26 | 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 27 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 28 | 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 29 | 3BCB02E1CBE594F0CD1623AD /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 31 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 32 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 33 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 34 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 35 | 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 36 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 38 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | 8418942A7DD0BF83080B943F /* libPods-Runner.a in Frameworks */, 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | 91AB6EA3A782CE6BD5EC5217 /* Frameworks */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 3BCB02E1CBE594F0CD1623AD /* libPods-Runner.a */, 60 | ); 61 | name = Frameworks; 62 | sourceTree = ""; 63 | }; 64 | 9740EEB11CF90186004384FC /* Flutter */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 68 | 3B80C3931E831B6300D905FE /* App.framework */, 69 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 70 | 9740EEBA1CF902C7004384FC /* Flutter.framework */, 71 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 72 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 73 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 74 | ); 75 | name = Flutter; 76 | sourceTree = ""; 77 | }; 78 | 97C146E51CF9000F007C117D = { 79 | isa = PBXGroup; 80 | children = ( 81 | 9740EEB11CF90186004384FC /* Flutter */, 82 | 97C146F01CF9000F007C117D /* Runner */, 83 | 97C146EF1CF9000F007C117D /* Products */, 84 | C6E5F4786BAFF94AE373AB1F /* Pods */, 85 | 91AB6EA3A782CE6BD5EC5217 /* Frameworks */, 86 | ); 87 | sourceTree = ""; 88 | }; 89 | 97C146EF1CF9000F007C117D /* Products */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 97C146EE1CF9000F007C117D /* Runner.app */, 93 | ); 94 | name = Products; 95 | sourceTree = ""; 96 | }; 97 | 97C146F01CF9000F007C117D /* Runner */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 101 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 102 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 103 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 104 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 105 | 97C147021CF9000F007C117D /* Info.plist */, 106 | 97C146F11CF9000F007C117D /* Supporting Files */, 107 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 108 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 109 | ); 110 | path = Runner; 111 | sourceTree = ""; 112 | }; 113 | 97C146F11CF9000F007C117D /* Supporting Files */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 97C146F21CF9000F007C117D /* main.m */, 117 | ); 118 | name = "Supporting Files"; 119 | sourceTree = ""; 120 | }; 121 | C6E5F4786BAFF94AE373AB1F /* Pods */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | ); 125 | name = Pods; 126 | sourceTree = ""; 127 | }; 128 | /* End PBXGroup section */ 129 | 130 | /* Begin PBXNativeTarget section */ 131 | 97C146ED1CF9000F007C117D /* Runner */ = { 132 | isa = PBXNativeTarget; 133 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 134 | buildPhases = ( 135 | 00BBAB36CB0AAF6E722EC5D6 /* [CP] Check Pods Manifest.lock */, 136 | 9740EEB61CF901F6004384FC /* Run Script */, 137 | 97C146EA1CF9000F007C117D /* Sources */, 138 | 97C146EB1CF9000F007C117D /* Frameworks */, 139 | 97C146EC1CF9000F007C117D /* Resources */, 140 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 141 | 62D4896B1F9147A8C1B964A3 /* [CP] Embed Pods Frameworks */, 142 | ); 143 | buildRules = ( 144 | ); 145 | dependencies = ( 146 | ); 147 | name = Runner; 148 | productName = Runner; 149 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 150 | productType = "com.apple.product-type.application"; 151 | }; 152 | /* End PBXNativeTarget section */ 153 | 154 | /* Begin PBXProject section */ 155 | 97C146E61CF9000F007C117D /* Project object */ = { 156 | isa = PBXProject; 157 | attributes = { 158 | LastUpgradeCheck = 0910; 159 | ORGANIZATIONNAME = "The Chromium Authors"; 160 | TargetAttributes = { 161 | 97C146ED1CF9000F007C117D = { 162 | CreatedOnToolsVersion = 7.3.1; 163 | ProvisioningStyle = Manual; 164 | }; 165 | }; 166 | }; 167 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 168 | compatibilityVersion = "Xcode 3.2"; 169 | developmentRegion = English; 170 | hasScannedForEncodings = 0; 171 | knownRegions = ( 172 | en, 173 | Base, 174 | ); 175 | mainGroup = 97C146E51CF9000F007C117D; 176 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 177 | projectDirPath = ""; 178 | projectRoot = ""; 179 | targets = ( 180 | 97C146ED1CF9000F007C117D /* Runner */, 181 | ); 182 | }; 183 | /* End PBXProject section */ 184 | 185 | /* Begin PBXResourcesBuildPhase section */ 186 | 97C146EC1CF9000F007C117D /* Resources */ = { 187 | isa = PBXResourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 191 | 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */, 192 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 193 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 194 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 195 | 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 196 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 197 | ); 198 | runOnlyForDeploymentPostprocessing = 0; 199 | }; 200 | /* End PBXResourcesBuildPhase section */ 201 | 202 | /* Begin PBXShellScriptBuildPhase section */ 203 | 00BBAB36CB0AAF6E722EC5D6 /* [CP] Check Pods Manifest.lock */ = { 204 | isa = PBXShellScriptBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | ); 208 | inputPaths = ( 209 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 210 | "${PODS_ROOT}/Manifest.lock", 211 | ); 212 | name = "[CP] Check Pods Manifest.lock"; 213 | outputPaths = ( 214 | "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | shellPath = /bin/sh; 218 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 219 | showEnvVarsInLog = 0; 220 | }; 221 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 222 | isa = PBXShellScriptBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | ); 226 | inputPaths = ( 227 | ); 228 | name = "Thin Binary"; 229 | outputPaths = ( 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | shellPath = /bin/sh; 233 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; 234 | }; 235 | 62D4896B1F9147A8C1B964A3 /* [CP] Embed Pods Frameworks */ = { 236 | isa = PBXShellScriptBuildPhase; 237 | buildActionMask = 2147483647; 238 | files = ( 239 | ); 240 | inputPaths = ( 241 | "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", 242 | "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", 243 | ); 244 | name = "[CP] Embed Pods Frameworks"; 245 | outputPaths = ( 246 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | shellPath = /bin/sh; 250 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; 251 | showEnvVarsInLog = 0; 252 | }; 253 | 9740EEB61CF901F6004384FC /* Run Script */ = { 254 | isa = PBXShellScriptBuildPhase; 255 | buildActionMask = 2147483647; 256 | files = ( 257 | ); 258 | inputPaths = ( 259 | ); 260 | name = "Run Script"; 261 | outputPaths = ( 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | shellPath = /bin/sh; 265 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 266 | }; 267 | /* End PBXShellScriptBuildPhase section */ 268 | 269 | /* Begin PBXSourcesBuildPhase section */ 270 | 97C146EA1CF9000F007C117D /* Sources */ = { 271 | isa = PBXSourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, 275 | 97C146F31CF9000F007C117D /* main.m in Sources */, 276 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | /* End PBXSourcesBuildPhase section */ 281 | 282 | /* Begin PBXVariantGroup section */ 283 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | 97C146FB1CF9000F007C117D /* Base */, 287 | ); 288 | name = Main.storyboard; 289 | sourceTree = ""; 290 | }; 291 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 292 | isa = PBXVariantGroup; 293 | children = ( 294 | 97C147001CF9000F007C117D /* Base */, 295 | ); 296 | name = LaunchScreen.storyboard; 297 | sourceTree = ""; 298 | }; 299 | /* End PBXVariantGroup section */ 300 | 301 | /* Begin XCBuildConfiguration section */ 302 | 97C147031CF9000F007C117D /* Debug */ = { 303 | isa = XCBuildConfiguration; 304 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 305 | buildSettings = { 306 | ALWAYS_SEARCH_USER_PATHS = NO; 307 | CLANG_ANALYZER_NONNULL = YES; 308 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 309 | CLANG_CXX_LIBRARY = "libc++"; 310 | CLANG_ENABLE_MODULES = YES; 311 | CLANG_ENABLE_OBJC_ARC = YES; 312 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 313 | CLANG_WARN_BOOL_CONVERSION = YES; 314 | CLANG_WARN_COMMA = YES; 315 | CLANG_WARN_CONSTANT_CONVERSION = YES; 316 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 317 | CLANG_WARN_EMPTY_BODY = YES; 318 | CLANG_WARN_ENUM_CONVERSION = YES; 319 | CLANG_WARN_INFINITE_RECURSION = YES; 320 | CLANG_WARN_INT_CONVERSION = YES; 321 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 322 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 323 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 324 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 325 | CLANG_WARN_STRICT_PROTOTYPES = YES; 326 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 327 | CLANG_WARN_UNREACHABLE_CODE = YES; 328 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 329 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 330 | COPY_PHASE_STRIP = NO; 331 | DEBUG_INFORMATION_FORMAT = dwarf; 332 | ENABLE_STRICT_OBJC_MSGSEND = YES; 333 | ENABLE_TESTABILITY = YES; 334 | GCC_C_LANGUAGE_STANDARD = gnu99; 335 | GCC_DYNAMIC_NO_PIC = NO; 336 | GCC_NO_COMMON_BLOCKS = YES; 337 | GCC_OPTIMIZATION_LEVEL = 0; 338 | GCC_PREPROCESSOR_DEFINITIONS = ( 339 | "DEBUG=1", 340 | "$(inherited)", 341 | ); 342 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 343 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 344 | GCC_WARN_UNDECLARED_SELECTOR = YES; 345 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 346 | GCC_WARN_UNUSED_FUNCTION = YES; 347 | GCC_WARN_UNUSED_VARIABLE = YES; 348 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 349 | MTL_ENABLE_DEBUG_INFO = YES; 350 | ONLY_ACTIVE_ARCH = YES; 351 | SDKROOT = iphoneos; 352 | TARGETED_DEVICE_FAMILY = "1,2"; 353 | }; 354 | name = Debug; 355 | }; 356 | 97C147041CF9000F007C117D /* Release */ = { 357 | isa = XCBuildConfiguration; 358 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 359 | buildSettings = { 360 | ALWAYS_SEARCH_USER_PATHS = NO; 361 | CLANG_ANALYZER_NONNULL = YES; 362 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 363 | CLANG_CXX_LIBRARY = "libc++"; 364 | CLANG_ENABLE_MODULES = YES; 365 | CLANG_ENABLE_OBJC_ARC = YES; 366 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 367 | CLANG_WARN_BOOL_CONVERSION = YES; 368 | CLANG_WARN_COMMA = YES; 369 | CLANG_WARN_CONSTANT_CONVERSION = YES; 370 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 371 | CLANG_WARN_EMPTY_BODY = YES; 372 | CLANG_WARN_ENUM_CONVERSION = YES; 373 | CLANG_WARN_INFINITE_RECURSION = YES; 374 | CLANG_WARN_INT_CONVERSION = YES; 375 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 376 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 377 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 378 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 379 | CLANG_WARN_STRICT_PROTOTYPES = YES; 380 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 381 | CLANG_WARN_UNREACHABLE_CODE = YES; 382 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 383 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 384 | COPY_PHASE_STRIP = NO; 385 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 386 | ENABLE_NS_ASSERTIONS = NO; 387 | ENABLE_STRICT_OBJC_MSGSEND = YES; 388 | GCC_C_LANGUAGE_STANDARD = gnu99; 389 | GCC_NO_COMMON_BLOCKS = YES; 390 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 391 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 392 | GCC_WARN_UNDECLARED_SELECTOR = YES; 393 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 394 | GCC_WARN_UNUSED_FUNCTION = YES; 395 | GCC_WARN_UNUSED_VARIABLE = YES; 396 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 397 | MTL_ENABLE_DEBUG_INFO = NO; 398 | SDKROOT = iphoneos; 399 | TARGETED_DEVICE_FAMILY = "1,2"; 400 | VALIDATE_PRODUCT = YES; 401 | }; 402 | name = Release; 403 | }; 404 | 97C147061CF9000F007C117D /* Debug */ = { 405 | isa = XCBuildConfiguration; 406 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 407 | buildSettings = { 408 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 409 | CODE_SIGN_STYLE = Manual; 410 | CURRENT_PROJECT_VERSION = 1; 411 | DEVELOPMENT_TEAM = ""; 412 | ENABLE_BITCODE = NO; 413 | FRAMEWORK_SEARCH_PATHS = ( 414 | "$(inherited)", 415 | "$(PROJECT_DIR)/Flutter", 416 | ); 417 | INFOPLIST_FILE = Runner/Info.plist; 418 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 419 | LIBRARY_SEARCH_PATHS = ( 420 | "$(inherited)", 421 | "$(PROJECT_DIR)/Flutter", 422 | ); 423 | PRODUCT_BUNDLE_IDENTIFIER = com.example.crptoDemo; 424 | PRODUCT_NAME = "$(TARGET_NAME)"; 425 | PROVISIONING_PROFILE_SPECIFIER = ""; 426 | VERSIONING_SYSTEM = "apple-generic"; 427 | }; 428 | name = Debug; 429 | }; 430 | 97C147071CF9000F007C117D /* Release */ = { 431 | isa = XCBuildConfiguration; 432 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 433 | buildSettings = { 434 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 435 | CODE_SIGN_STYLE = Manual; 436 | CURRENT_PROJECT_VERSION = 1; 437 | DEVELOPMENT_TEAM = ""; 438 | ENABLE_BITCODE = NO; 439 | FRAMEWORK_SEARCH_PATHS = ( 440 | "$(inherited)", 441 | "$(PROJECT_DIR)/Flutter", 442 | ); 443 | INFOPLIST_FILE = Runner/Info.plist; 444 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 445 | LIBRARY_SEARCH_PATHS = ( 446 | "$(inherited)", 447 | "$(PROJECT_DIR)/Flutter", 448 | ); 449 | PRODUCT_BUNDLE_IDENTIFIER = com.example.crptoDemo; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | PROVISIONING_PROFILE_SPECIFIER = ""; 452 | VERSIONING_SYSTEM = "apple-generic"; 453 | }; 454 | name = Release; 455 | }; 456 | /* End XCBuildConfiguration section */ 457 | 458 | /* Begin XCConfigurationList section */ 459 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 460 | isa = XCConfigurationList; 461 | buildConfigurations = ( 462 | 97C147031CF9000F007C117D /* Debug */, 463 | 97C147041CF9000F007C117D /* Release */, 464 | ); 465 | defaultConfigurationIsVisible = 0; 466 | defaultConfigurationName = Release; 467 | }; 468 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 469 | isa = XCConfigurationList; 470 | buildConfigurations = ( 471 | 97C147061CF9000F007C117D /* Debug */, 472 | 97C147071CF9000F007C117D /* Release */, 473 | ); 474 | defaultConfigurationIsVisible = 0; 475 | defaultConfigurationName = Release; 476 | }; 477 | /* End XCConfigurationList section */ 478 | }; 479 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 480 | } 481 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 56 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 75 | 77 | 83 | 84 | 85 | 86 | 88 | 89 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : FlutterAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /ios/Runner/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | #include "GeneratedPluginRegistrant.h" 3 | 4 | @implementation AppDelegate 5 | 6 | - (BOOL)application:(UIApplication *)application 7 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 8 | [GeneratedPluginRegistrant registerWithRegistry:self]; 9 | // Override point for customization after application launch. 10 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /ios/Runner/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 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /ios/Runner/Base.lproj/Main.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 | -------------------------------------------------------------------------------- /ios/Runner/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 | crpto_demo 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ios/Runner/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char* argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /lib/crypto/aes_pkcs/base_padding.dart: -------------------------------------------------------------------------------- 1 | import "dart:typed_data"; 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | /// Base implementation of [Padding] which provides shared methods. 6 | abstract class BasePadding implements Padding { 7 | 8 | Uint8List process(bool pad, Uint8List data) { 9 | if (pad) { 10 | var out = new Uint8List.fromList(data); 11 | var len = addPadding(out, 0); 12 | return out; 13 | } else { 14 | var len = padCount(data); 15 | return new Uint8List.fromList(data.sublist(0, len)); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /lib/crypto/aes_pkcs/padded_block_cipher.dart: -------------------------------------------------------------------------------- 1 | import "dart:typed_data"; 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | /// The standard implementation of [PaddedBlockCipher]. 6 | class PaddedBlockCipherImpl implements PaddedBlockCipher { 7 | final Padding padding; 8 | final BlockCipher cipher; 9 | 10 | bool _encrypting; 11 | 12 | PaddedBlockCipherImpl(this.padding, this.cipher); 13 | 14 | String get algorithmName => 15 | cipher.algorithmName + "/" + padding.algorithmName; 16 | 17 | int get blockSize => cipher.blockSize; 18 | 19 | void reset() { 20 | _encrypting = null; 21 | cipher.reset(); 22 | } 23 | 24 | void init(bool forEncryption, CipherParameters params) { 25 | _encrypting = forEncryption; 26 | cipher.init(forEncryption, params); 27 | padding.init(params); 28 | } 29 | 30 | Uint8List process(Uint8List data) { 31 | var inputBlocks = (data.length + blockSize - 1) ~/ blockSize; 32 | 33 | var outputBlocks; 34 | if (_encrypting) { 35 | outputBlocks = (data.length + blockSize) ~/ blockSize; 36 | } else { 37 | if ((data.length % blockSize) != 0) { 38 | throw new ArgumentError( 39 | "Input data length must be a multiple of cipher's block size"); 40 | } 41 | outputBlocks = inputBlocks; 42 | } 43 | 44 | var out = new Uint8List(outputBlocks * blockSize); 45 | 46 | for (var i = 0; i < (inputBlocks - 1); i++) { 47 | var offset = (i * blockSize); 48 | processBlock(data, offset, out, offset); 49 | } 50 | 51 | var lastBlockOffset = ((inputBlocks - 1) * blockSize); 52 | var lastBlockSize = doFinal(data, lastBlockOffset, out, lastBlockOffset); 53 | 54 | return out.sublist(0, lastBlockOffset + lastBlockSize); 55 | } 56 | 57 | int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) { 58 | return cipher.processBlock(inp, inpOff, out, outOff); 59 | } 60 | 61 | int doFinal(Uint8List inp, int inpOff, Uint8List out, int outOff) { 62 | if (_encrypting) { 63 | var lastInputBlock = new Uint8List(blockSize) 64 | ..setAll(0, inp.sublist(inpOff)); 65 | 66 | var remainder = inp.length - inpOff; 67 | 68 | if (remainder < blockSize) { 69 | // Padding goes embedded in last block of data 70 | padding.addPadding(lastInputBlock, (inp.length - inpOff)); 71 | 72 | processBlock(lastInputBlock, 0, out, outOff); 73 | 74 | return blockSize; 75 | } else { 76 | // Padding goes alone in an additional block 77 | processBlock(inp, inpOff, out, outOff); 78 | 79 | padding.addPadding(lastInputBlock, 0); 80 | 81 | processBlock(lastInputBlock, 0, out, outOff + blockSize); 82 | 83 | return 2 * blockSize; 84 | } 85 | } else { 86 | // Decrypt last block and remove padding 87 | processBlock(inp, inpOff, out, outOff); 88 | 89 | var padCount = padding.padCount(out.sublist(outOff)); 90 | 91 | var padOffsetInBlock = blockSize - padCount; 92 | 93 | out.fillRange(outOff + padOffsetInBlock, out.length, 0); 94 | 95 | return padOffsetInBlock; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /lib/crypto/aes_pkcs/pkcs7.dart: -------------------------------------------------------------------------------- 1 | import "dart:typed_data"; 2 | 3 | import 'package:pointycastle/pointycastle.dart'; 4 | 5 | import "./base_padding.dart"; 6 | import './ufixnum.dart'; 7 | 8 | /// A [Padding] that adds PKCS7/PKCS5 padding to a block. 9 | class PKCS7Padding extends BasePadding { 10 | String get algorithmName => "PKCS7"; 11 | 12 | void init([CipherParameters params]) { 13 | // nothing to do. 14 | } 15 | 16 | int addPadding(Uint8List data, int offset) { 17 | var code = (data.length - offset); 18 | 19 | while (offset < data.length) { 20 | data[offset] = code; 21 | offset++; 22 | } 23 | 24 | return code; 25 | } 26 | 27 | int padCount(Uint8List data) { 28 | var count = clip8(data[data.length - 1]); 29 | 30 | if (count > data.length || count == 0) { 31 | throw new ArgumentError("Invalid or corrupted pad block"); 32 | } 33 | 34 | for (var i = 1; i <= count; i++) { 35 | if (data[data.length - i] != count) { 36 | throw new ArgumentError("Invalid or corrupted pad block"); 37 | } 38 | } 39 | 40 | return count; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/crypto/aes_pkcs/ufixnum.dart: -------------------------------------------------------------------------------- 1 | import "dart:typed_data"; 2 | 3 | const _MASK_3 = 0x07; 4 | const _MASK_5 = 0x1F; 5 | const _MASK_6 = 0x3F; 6 | const _MASK_8 = 0xFF; 7 | const _MASK_16 = 0xFFFF; 8 | const _MASK_32 = 0xFFFFFFFF; 9 | 10 | final _MASK32_HI_BITS = [ 11 | 0xFFFFFFFF, 0x7FFFFFFF, 0x3FFFFFFF, 0x1FFFFFFF, 0x0FFFFFFF, 0x07FFFFFF, 0x03FFFFFF, 0x01FFFFFF, 12 | 0x00FFFFFF, 0x007FFFFF, 0x003FFFFF, 0x001FFFFF, 0x000FFFFF, 0x0007FFFF, 0x0003FFFF, 0x0001FFFF, 13 | 0x0000FFFF, 0x00007FFF, 0x00003FFF, 0x00001FFF, 0x00000FFF, 0x000007FF, 0x000003FF, 0x000001FF, 14 | 0x000000FF, 0x0000007F, 0x0000003F, 0x0000001F, 0x0000000F, 0x00000007, 0x00000003, 0x00000001, 15 | 0x00000000 16 | ]; 17 | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////// 19 | // 8 bit operations 20 | // 21 | int clip8(int x) => (x & _MASK_8); 22 | 23 | int csum8(int x, int y) => sum8(clip8(x), clip8(y)); 24 | int sum8(int x, int y) { 25 | assert((x >= 0) && (x <= _MASK_8)); 26 | assert((y >= 0) && (y <= _MASK_8)); 27 | return ((x + y) & _MASK_8); 28 | } 29 | 30 | int csub8(int x, int y) => sub8(clip8(x), clip8(y)); 31 | int sub8(int x, int y) { 32 | assert((x >= 0) && (x <= _MASK_8)); 33 | assert((y >= 0) && (y <= _MASK_8)); 34 | return ((x - y) & _MASK_8); 35 | } 36 | 37 | int cshiftl8(int x, int n) => shiftl8(clip8(x), n); 38 | int shiftl8(int x, int n) { 39 | assert((x >= 0) && (x <= _MASK_8)); 40 | return ((x << (n & _MASK_3)) & _MASK_8); 41 | } 42 | 43 | int cshiftr8(int x, int n) => shiftr8(clip8(x), n); 44 | int shiftr8(int x, int n) { 45 | assert((x >= 0) && (x <= _MASK_8)); 46 | return (x >> (n & _MASK_3)); 47 | } 48 | 49 | int cneg8(int x) => neg8(clip8(x)); 50 | int neg8(int x) { 51 | assert((x >= 0) && (x <= _MASK_8)); 52 | return (-x & _MASK_8); 53 | } 54 | 55 | int cnot8(int x) => not8(clip8(x)); 56 | int not8(int x) { 57 | assert((x >= 0) && (x <= _MASK_8)); 58 | return (~x & _MASK_8); 59 | } 60 | 61 | int crotl8(int x, int n) => rotl8(clip8(x), n); 62 | int rotl8(int x, int n) { 63 | assert(n >= 0); 64 | assert((x >= 0) && (x <= _MASK_8)); 65 | n &= _MASK_3; 66 | return ((x << n) & _MASK_8) | (x >> (8 - n)); 67 | } 68 | 69 | int crotr8(int x, int n) => rotr8(clip8(x), n); 70 | int rotr8(int x, int n) { 71 | assert(n >= 0); 72 | assert((x >= 0) && (x <= _MASK_8)); 73 | n &= _MASK_3; 74 | return ((x >> n) & _MASK_8) | ((x << (8 - n)) & _MASK_8); 75 | } 76 | 77 | 78 | //////////////////////////////////////////////////////////////////////////////////////////////////// 79 | // 16 bit operations 80 | // 81 | int clip16(int x) => (x & _MASK_16); 82 | 83 | 84 | //////////////////////////////////////////////////////////////////////////////////////////////////// 85 | // 32 bit operations 86 | // 87 | int clip32(int x) => (x & _MASK_32); 88 | 89 | int csum32(int x, int y) => sum32(clip32(x), clip32(y)); 90 | int sum32(int x, int y) { 91 | assert((x >= 0) && (x <= _MASK_32)); 92 | assert((y >= 0) && (y <= _MASK_32)); 93 | return ((x + y) & _MASK_32); 94 | } 95 | 96 | int csub32(int x, int y) => sub32(clip32(x), clip32(y)); 97 | int sub32(int x, int y) { 98 | assert((x >= 0) && (x <= _MASK_32)); 99 | assert((y >= 0) && (y <= _MASK_32)); 100 | return ((x - y) & _MASK_32); 101 | } 102 | 103 | int cshiftl32(int x, int n) => shiftl32(clip32(x), n); 104 | int shiftl32(int x, int n) { 105 | assert((x >= 0) && (x <= _MASK_32)); 106 | n &= _MASK_5; 107 | x &= _MASK32_HI_BITS[n]; 108 | return ((x << n) & _MASK_32); 109 | } 110 | 111 | int cshiftr32(int x, int n) => shiftr32(clip32(x), n); 112 | int shiftr32(int x, int n) { 113 | assert((x >= 0) && (x <= _MASK_32)); 114 | n &= _MASK_5; 115 | return (x >> n); 116 | } 117 | 118 | int cneg32(int x) => neg32(clip32(x)); 119 | int neg32(int x) { 120 | assert((x >= 0) && (x <= _MASK_32)); 121 | return (-x & _MASK_32); 122 | } 123 | 124 | int cnot32(int x) => not32(clip32(x)); 125 | int not32(int x) { 126 | assert((x >= 0) && (x <= _MASK_32)); 127 | return (~x & _MASK_32); 128 | } 129 | 130 | int crotl32(int x, int n) => rotl32(clip32(x), n); 131 | int rotl32(int x, int n) { 132 | assert(n >= 0); 133 | assert((x >= 0) && (x <= _MASK_32)); 134 | n &= _MASK_5; 135 | return shiftl32(x, n) | (x >> (32 - n)); 136 | } 137 | 138 | int crotr32(int x, int n) => rotr32(clip32(x), n); 139 | int rotr32(int x, int n) { 140 | assert(n >= 0); 141 | assert((x >= 0) && (x <= _MASK_32)); 142 | n &= _MASK_5; 143 | return (x >> n) | shiftl32(x, (32 - n)); 144 | } 145 | 146 | /** 147 | * Packs a 32 bit integer into a byte buffer. The [out] parameter can be an [Uint8List] or a 148 | * [ByteData] if you will run it several times against the same buffer and want faster execution. 149 | */ 150 | void pack32(int x, dynamic out, int offset, Endian endian) { 151 | assert((x >= 0) && (x <= _MASK_32)); 152 | if (out is! ByteData) { 153 | out = new ByteData.view(out.buffer); 154 | } 155 | (out as ByteData).setUint32(offset, x, endian); 156 | } 157 | 158 | /** 159 | * Unpacks a 32 bit integer from a byte buffer. The [inp] parameter can be an [Uint8List] or a 160 | * [ByteData] if you will run it several times against the same buffer and want faster execution. 161 | */ 162 | int unpack32(dynamic inp, int offset, Endian endian) { 163 | if (inp is! ByteData) { 164 | inp = new ByteData.view(inp.buffer); 165 | } 166 | return (inp as ByteData).getUint32(offset, endian); 167 | } 168 | 169 | 170 | //////////////////////////////////////////////////////////////////////////////////////////////////// 171 | // 64 bit operations 172 | // 173 | class Register64 { 174 | 175 | static final Register64 _MAX_VALUE = new Register64(0xFFFFFFFF, 0xFFFFFFFF); 176 | 177 | int _hi32; 178 | int _lo32; 179 | 180 | Register64([dynamic hiOrLo32OrY=0, int lo32=null]) { 181 | set(hiOrLo32OrY, lo32); 182 | } 183 | 184 | int get lo32 => _lo32; 185 | int get hi32 => _hi32; 186 | 187 | //bool operator ==(Register64 y) => ((_hi32 == y._hi32) && (_lo32 == y._lo32)); 188 | bool operator < (Register64 y) => ((_hi32 < y._hi32) || ((_hi32 == y._hi32) && (_lo32 < y._lo32))); 189 | bool operator <=(Register64 y) => ((this < y) || (this == y)); 190 | bool operator > (Register64 y) => ((_hi32 > y._hi32) || ((_hi32 == y._hi32) && (_lo32 > y._lo32))); 191 | bool operator >=(Register64 y) => ((this > y) || (this == y)); 192 | 193 | void set(dynamic hiOrLo32OrY, [int lo32=null]) { 194 | if (lo32 == null) { 195 | if (hiOrLo32OrY is Register64) { 196 | _hi32 = hiOrLo32OrY._hi32; 197 | _lo32 = hiOrLo32OrY._lo32; 198 | } else { 199 | assert(hiOrLo32OrY <= _MASK_32); 200 | _hi32 = 0; 201 | _lo32 = hiOrLo32OrY; 202 | } 203 | } else { 204 | assert(hiOrLo32OrY <= _MASK_32); 205 | assert(lo32 <= _MASK_32); 206 | _hi32 = hiOrLo32OrY; 207 | _lo32 = lo32; 208 | } 209 | } 210 | 211 | void sum(dynamic y) { 212 | if (y is int) { 213 | y &= _MASK_32; 214 | int slo32 = (_lo32 + y); 215 | _lo32 = (slo32 & _MASK_32); 216 | if (slo32 != _lo32) { 217 | _hi32++; 218 | _hi32 &= _MASK_32; 219 | } 220 | } else { 221 | int slo32 = (_lo32 + y._lo32); 222 | _lo32 = (slo32 & _MASK_32); 223 | int carry = ((slo32 != _lo32) ? 1 : 0); 224 | _hi32 = (((_hi32 + y._hi32 + carry) as int) & _MASK_32); 225 | } 226 | } 227 | 228 | void sub(dynamic y) { 229 | // TODO: optimize sub() ??? 230 | sum(new Register64(y)..neg()); 231 | } 232 | 233 | void mul(dynamic y) { 234 | if (y is int) { 235 | final lo32 = _lo32*y; 236 | final carry = (lo32 ~/ 0x100000000); // TODO: use shift right when bug 17715 is fixed 237 | final hi32 = clip32(_hi32*y) + carry; 238 | 239 | _hi32 = clip32(hi32); 240 | _lo32 = clip32(lo32); 241 | } else { 242 | final lo32 = _lo32*y._lo32; 243 | final carry = (lo32 ~/ 0x100000000); // TODO: use shift right when bug 17715 is fixed 244 | final hi32 = clip32(_hi32*y._lo32) + clip32(_lo32*y._hi32) + carry; 245 | 246 | _hi32 = clip32(hi32); 247 | _lo32 = clip32(lo32); 248 | } 249 | } 250 | 251 | void neg() { 252 | not(); 253 | sum(1); 254 | } 255 | 256 | void not() { 257 | _hi32 = (~_hi32 & _MASK_32); 258 | _lo32 = (~_lo32 & _MASK_32); 259 | } 260 | 261 | void and(Register64 y) { 262 | _hi32 &= y._hi32; 263 | _lo32 &= y._lo32; 264 | } 265 | 266 | void or(Register64 y) { 267 | _hi32 |= y._hi32; 268 | _lo32 |= y._lo32; 269 | } 270 | 271 | void xor(Register64 y) { 272 | _hi32 ^= y._hi32; 273 | _lo32 ^= y._lo32; 274 | } 275 | 276 | void shiftl(int n) { 277 | n &= _MASK_6; 278 | if (n == 0) { 279 | // do nothing 280 | } else if (n >= 32) { 281 | _hi32 = shiftl32(_lo32, (n - 32)); 282 | _lo32 = 0; 283 | } else { 284 | _hi32 = shiftl32(_hi32, n); 285 | _hi32 |= _lo32 >> (32 - n); 286 | _lo32 = shiftl32(_lo32, n); 287 | } 288 | } 289 | 290 | void shiftr(int n) { 291 | n &= _MASK_6; 292 | if (n == 0) { 293 | // do nothing 294 | } else if (n >= 32) { 295 | _lo32 = _hi32 >> (n - 32); 296 | _hi32 = 0; 297 | } else { 298 | _lo32 = _lo32 >> n; 299 | _lo32 |= shiftl32(_hi32, 32 - n); 300 | _hi32 = _hi32 >> n; 301 | } 302 | } 303 | 304 | void rotl(int n) { 305 | n &= _MASK_6; 306 | if (n == 0) { 307 | // do nothing 308 | } else { 309 | if (n >= 32) { 310 | var swap = _hi32; 311 | _hi32 = _lo32; 312 | _lo32 = swap; 313 | n -= 32; 314 | } 315 | 316 | if (n == 0) { 317 | // do nothing 318 | } else { 319 | var hi32 = _hi32; 320 | _hi32 = shiftl32(_hi32, n); 321 | _hi32 |= _lo32 >> (32 - n); 322 | _lo32 = shiftl32(_lo32, n); 323 | _lo32 |= hi32 >> (32 - n); 324 | } 325 | } 326 | } 327 | 328 | void rotr(int n) { 329 | n &= _MASK_6; 330 | if (n == 0) { 331 | // do nothing 332 | } else { 333 | if (n >= 32) { 334 | var swap = _hi32; 335 | _hi32 = _lo32; 336 | _lo32 = swap; 337 | n -= 32; 338 | } 339 | 340 | if (n == 0) { 341 | // do nothing 342 | } else { 343 | var hi32 = _hi32; 344 | _hi32 = _hi32 >> n; 345 | _hi32 |= shiftl32(_lo32, (32 - n)); 346 | _lo32 = _lo32 >> n; 347 | _lo32 |= shiftl32(hi32, (32 - n)); 348 | } 349 | } 350 | } 351 | 352 | /** 353 | * Packs a 64 bit integer into a byte buffer. The [out] parameter can be an [Uint8List] or a 354 | * [ByteData] if you will run it several times against the same buffer and want faster execution. 355 | */ 356 | void pack(dynamic out, int offset, Endian endian) { 357 | switch (endian) { 358 | case Endian.big: 359 | pack32(hi32, out, offset , endian); 360 | pack32(lo32, out, offset + 4, endian); 361 | break; 362 | 363 | case Endian.little: 364 | pack32(hi32, out, offset + 4, endian); 365 | pack32(lo32, out, offset , endian); 366 | break; 367 | 368 | default: 369 | throw new UnsupportedError("Invalid endianness: ${endian}"); 370 | } 371 | } 372 | 373 | /** 374 | * Unpacks a 32 bit integer from a byte buffer. The [inp] parameter can be an [Uint8List] or a 375 | * [ByteData] if you will run it several times against the same buffer and want faster execution. 376 | */ 377 | void unpack(dynamic inp, int offset, Endian endian) { 378 | switch (endian) { 379 | case Endian.big: 380 | _hi32 = unpack32(inp, offset , endian); 381 | _lo32 = unpack32(inp, offset+4, endian); 382 | break; 383 | 384 | case Endian.little: 385 | _hi32 = unpack32(inp, offset+4, endian); 386 | _lo32 = unpack32(inp, offset , endian); 387 | break; 388 | 389 | default: 390 | throw new UnsupportedError("Invalid endianness: ${endian}"); 391 | } 392 | } 393 | 394 | String toString() { 395 | var sb = new StringBuffer(); 396 | _padWrite(sb, _hi32); 397 | _padWrite(sb, _lo32); 398 | return sb.toString(); 399 | } 400 | 401 | void _padWrite(StringBuffer sb, int value) { 402 | var str = value.toRadixString(16); 403 | for (var i = (8 - str.length); i > 0; i--) { 404 | sb.write("0"); 405 | } 406 | sb.write(str); 407 | } 408 | 409 | } 410 | 411 | class Register64List { 412 | 413 | final List _list; 414 | 415 | Register64List.from(List> values) : 416 | _list = new List.generate( 417 | values.length, (i) => new Register64(values[i][0], values[i][1])); 418 | 419 | Register64List(int length) : 420 | _list = new List.generate(length, (_) => new Register64()); 421 | 422 | int get length => _list.length; 423 | 424 | Register64 operator [](int index) => _list[index]; 425 | 426 | void fillRange(int start, int end, dynamic hiOrLo32OrY, [int lo32=null]) { 427 | for (var i = start; i < end; i++) { 428 | _list[i].set(hiOrLo32OrY, lo32); 429 | } 430 | } 431 | 432 | void setRange(int start, int end, Register64List list) { 433 | for (var i = start; i < end; i++) { 434 | _list[i].set(list[i]); 435 | } 436 | } 437 | 438 | String toString() { 439 | var sb = new StringBuffer("("); 440 | for (var i = 0; i < _list.length; i++) { 441 | if (i > 0) { 442 | sb.write(", "); 443 | } 444 | sb.write(_list[i].toString()); 445 | } 446 | sb.write(")"); 447 | return sb.toString(); 448 | } 449 | 450 | } 451 | -------------------------------------------------------------------------------- /lib/crypto/bbs/bbs.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, . All rights reserved. Use of this source code 2 | // is governed by a BSD-style license that can be found in the LICENSE file. 3 | 4 | /// The bbs library. 5 | /// 6 | /// This is an awesome library. More dartdocs go here. 7 | 8 | // TODO: Export any libraries intended for clients of this package. 9 | 10 | export 'src/bbs_base.dart'; 11 | -------------------------------------------------------------------------------- /lib/crypto/bbs/src/bbs_base.dart: -------------------------------------------------------------------------------- 1 | export 'bbs_blum.dart'; 2 | export 'bbs_primes.dart'; -------------------------------------------------------------------------------- /lib/crypto/bbs/src/bbs_blum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Modified by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'dart:math' show Random, log; 7 | import 'bbs_primes.dart' as primes; 8 | 9 | class BlumBlumShub implements Random { 10 | BigInt n; 11 | BigInt state; 12 | 13 | BlumBlumShub([int bits = 256, Random random]) { 14 | this.n = generateN(bits, random); 15 | var length = this.n.bitLength; 16 | this.seed = primes.getRandBits(length, random); 17 | } 18 | 19 | set seed(BigInt seed) => this.state = seed % this.n; 20 | 21 | static BigInt getPrime(int bits, [Random random]) { 22 | while (true) { 23 | var p = primes.bigPrime(bits, random); 24 | if (BigInt.from(3) == (p & BigInt.from(3))) return p; 25 | } 26 | } 27 | 28 | static BigInt generateN(int bits, [Random random]) { 29 | var p = getPrime(bits ~/ 2, random); 30 | while (true) { 31 | var q = getPrime(bits ~/ 2, random); 32 | 33 | if (p != q) return p * q; 34 | } 35 | } 36 | 37 | BigInt next(int numBits) { 38 | var result = BigInt.zero; 39 | 40 | for (int i = 0; i < numBits; i++) { 41 | this.state = this.state.modPow(BigInt.two, this.n); 42 | result = toBig((result << 1) | (toBig(this.state & BigInt.one))); 43 | } 44 | 45 | return result; 46 | } 47 | 48 | static BigInt toBig(n) { 49 | if (n is int) return new BigInt.from(n); 50 | if (n is BigInt) return n; 51 | throw new ArgumentError.value(n); 52 | } 53 | 54 | static int toInt(n) { 55 | if (n is int) return n; 56 | if (n is BigInt) return n.toInt(); 57 | throw new ArgumentError.value(n); 58 | } 59 | 60 | double nextDouble() => throw new UnimplementedError(); 61 | 62 | static int neededBits(int max) { 63 | if (0 == max || 1 == max) return 1; 64 | return (log(max + 1) / log(2)) 65 | .ceil(); // +1 because max would be no of possibilites 66 | } 67 | 68 | bool nextBool() { 69 | return 1 == next(1).toInt() ? true : false; 70 | } 71 | 72 | int nextInt(int max) { 73 | var bits = neededBits(max); 74 | var _max = toBig(max); 75 | while (true) { 76 | var value = next(bits); 77 | if (value < _max) return toInt(value); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /lib/crypto/bbs/src/bbs_primes.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Modified by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'dart:math' show Random; 7 | 8 | // Copies bigInt, then judges whether a large number is prime or not. 9 | class CopyBigInt { 10 | final BigInt a; 11 | final int _s = 100; // s is random 12 | 13 | CopyBigInt(this.a); 14 | 15 | BigInt get bigInt => a; 16 | 17 | // (a*b)%c a,b,c<2^63 18 | int modMult(int a, int b, int mod) { 19 | a = a % mod; 20 | b = b % mod; 21 | 22 | int ans = 0; 23 | 24 | while (b != 0) { 25 | if ((b & 1) != 0) { 26 | ans = ans + a; 27 | if (ans >= mod) ans = ans - mod; 28 | } 29 | a = a << 1; 30 | if (a >= mod) a = a - mod; 31 | b = b >> 1; 32 | } 33 | 34 | return ans; 35 | } 36 | 37 | // a^b%mod 38 | int modPow(int a, int b, int mod) { 39 | int ans = 1; 40 | a = a % mod; 41 | 42 | while (b != 0) { 43 | if ((b & 1) != 0) { 44 | ans = modMult(ans, a, mod); 45 | } 46 | a = modMult(a, a, mod); 47 | b = b >> 1; 48 | } 49 | 50 | return ans; 51 | } 52 | 53 | // Verifies wether n is composite number or not. 54 | // Return true, it must be. 55 | // Return false, it may be. 56 | // n-1=x*2^t, a^(n-1)=1(mod n) 57 | bool check(int a, int n, int x, int t) { 58 | int ret = modPow(a, x, n); 59 | int last = ret; 60 | 61 | for (int i = 1; i <= t; i++) { 62 | ret = modMult(ret, ret, n); 63 | if (ret == 1 && last != 1 && last != n - 1) 64 | return true; //composite number 65 | last = ret; 66 | } 67 | 68 | if (ret != 1) 69 | return true; 70 | else 71 | return false; 72 | } 73 | 74 | // Miller Rabin algorithm prime judging. 75 | // Return true, it may be pseudo prime, but the probability is minimal. 76 | // Return false, it is composite number. 77 | bool millerRabin(int n) { 78 | if (n < 2) return false; 79 | if (n == 2) return true; 80 | if ((n & 1) == 0) return false; // even number 81 | 82 | int x = n - 1; 83 | int t = 0; 84 | 85 | while ((x & 1) == 0) { 86 | x >>= 1; 87 | t++; 88 | } 89 | 90 | // var max = 1 << 32; 91 | for (int i = 0; i < _s; i++) { 92 | // Random().nextInt(max) % (n - 1) + 1; 93 | int a = this.a.toInt() % (n - 1) + 1; 94 | if (check(a, n, x, t)) return false; //composite number 95 | } 96 | 97 | return true; 98 | } 99 | 100 | // Judges whether a large number is prime 101 | bool isProbablePrime(int s) { 102 | return millerRabin(s); 103 | } 104 | } 105 | 106 | BigInt bigPrime([int bits = 256, Random random]) { 107 | var candidate = getRandBits(bits, random); 108 | 109 | candidate = candidate | BigInt.one; // Ensure uneven 110 | 111 | while (true) { 112 | var cbi = new CopyBigInt(candidate); 113 | if (cbi.isProbablePrime(5)) return candidate; 114 | candidate = candidate + BigInt.two; 115 | } 116 | } 117 | 118 | BigInt getRandBits(int n, [Random random]) { 119 | if (0 >= n) throw new ArgumentError.value(n); 120 | if (null == random) random = new Random(); 121 | 122 | var l = new List.generate(n, (_) => random.nextInt(2)); 123 | var i = 0; 124 | return l.fold(BigInt.one, (BigInt acc, int c) { 125 | i++; 126 | if (0 == c) { 127 | return acc; 128 | } 129 | return acc + BigInt.two.pow(i - 1); 130 | }); 131 | } 132 | -------------------------------------------------------------------------------- /lib/crypto/crypto_aes.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'dart:convert'; 7 | import 'dart:typed_data'; 8 | 9 | import 'package:pointycastle/pointycastle.dart' as pointy; 10 | import 'package:pointycastle/export.dart' as pointy; 11 | 12 | import './aes_pkcs/padded_block_cipher.dart' as padded; 13 | import './aes_pkcs/pkcs7.dart' as pkcs; 14 | 15 | class AESEncoder { 16 | final Uint8List key; 17 | 18 | final _cipher = pointy.AESFastEngine(); 19 | 20 | AESEncoder(String key) : key = Uint8List.fromList(utf8.encode(key)); 21 | 22 | AESEncoder.fromBytes(this.key); 23 | 24 | String encode(String input) { 25 | var params = pointy.KeyParameter(this.key); 26 | 27 | var padding = pkcs.PKCS7Padding(); 28 | 29 | var pbc = padded.PaddedBlockCipherImpl(padding, _cipher) 30 | ..reset() 31 | ..init(true, params); 32 | 33 | var data = Uint8List.fromList(utf8.encode(input)); 34 | var output = pbc.process(data); 35 | 36 | return base64.encode(output); 37 | } 38 | } 39 | 40 | class AESDecoder { 41 | final Uint8List key; 42 | 43 | final _cipher = pointy.AESFastEngine(); 44 | 45 | AESDecoder(String key) : key = Uint8List.fromList(utf8.encode(key)); 46 | 47 | AESDecoder.fromBytes(this.key); 48 | 49 | String decode(String input) { 50 | var params = pointy.KeyParameter(this.key); 51 | 52 | var padding = pkcs.PKCS7Padding(); 53 | 54 | var pbc = padded.PaddedBlockCipherImpl(padding, _cipher) 55 | ..reset() 56 | ..init(false, params); 57 | 58 | var data = base64.decode(input); 59 | var output = pbc.process(data); 60 | 61 | return utf8.decode(output); 62 | } 63 | } 64 | 65 | class AES { 66 | final AESEncoder _encoder; 67 | 68 | final AESDecoder _decoder; 69 | 70 | factory AES(String key) => 71 | AES.fromBytes(Uint8List.fromList(utf8.encode(key))); 72 | 73 | factory AES.fromBytes(Uint8List key) { 74 | return AES.from(AESEncoder.fromBytes(key), AESDecoder.fromBytes(key)); 75 | } 76 | 77 | AES.from(AESEncoder encoder, AESDecoder decoder) 78 | : _encoder = encoder, 79 | _decoder = decoder; 80 | 81 | String encode(String input) => _encoder.encode(input); 82 | String decode(String input) => _decoder.decode(input); 83 | } 84 | -------------------------------------------------------------------------------- /lib/crypto/crypto_provider.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'dart:convert'; 7 | import 'dart:io'; 8 | import 'dart:typed_data'; 9 | import 'dart:math' as Math; 10 | 11 | import 'package:crypto/crypto.dart'; 12 | 13 | import './des/tripledes.dart' as DESUtils; 14 | import './crypto_aes.dart'; 15 | import './rsa/rsa.dart' show KeyPair; 16 | import './rsa/rsa_block.dart' show RSABlock; 17 | import './rsa/rsa_key_formatter.dart' show RSAKeyFormatter; 18 | 19 | /// [DYFCryptoProvider] provides Base64, 16/32 bit MD5, AES, RSA, etc. 20 | class DYFCryptoProvider { 21 | /// Converts a string to base64. 22 | static yf_base64Encode(String string) { 23 | if (string == null) throw new ArgumentError("The argument is null"); 24 | 25 | // get a base64 encoder instance. 26 | var encoder = new Base64Encoder(); 27 | 28 | // utf8 encoding. 29 | var list = utf8.encode(string); 30 | // encode a string to Base64. 31 | var encodedString = encoder.convert(list); 32 | 33 | return encodedString; 34 | } 35 | 36 | /// Converts a base64 encoded string to a string or a `Uint8List`. 37 | static yf_base64Decode(String encodedString, {bool createUint8List = false}) { 38 | if (encodedString == null) throw new ArgumentError("encodedString is null"); 39 | 40 | // get a base64 decoder instance. 41 | var decoder = Base64Decoder(); 42 | 43 | // decode a base64 encoded string to a List of bytes. 44 | var bytes = decoder.convert(encodedString); 45 | 46 | if (createUint8List) { 47 | return createUint8ListFromList(bytes); 48 | } 49 | 50 | var output = utf8.decode(bytes); 51 | 52 | return output; 53 | } 54 | 55 | /// Converts a List of bytes to a base64 encoded string. 56 | static base64EncodeList(List bytes) { 57 | if (bytes == null) throw new ArgumentError("The list is null"); 58 | 59 | // get a base64 encoder instance 60 | var encoder = new Base64Encoder(); 61 | 62 | // encode a List of bytes - use line breaks 63 | var out = encoder.convert(bytes); 64 | 65 | return out; 66 | } 67 | 68 | /// Converts a base64 encoded List of bytes to a string or a `Uint8List`. 69 | static base64DecodeList(List bytes, {bool createUint8List = false}) { 70 | if (bytes == null) throw new ArgumentError("The list is null"); 71 | 72 | // get a base64 decoder instance 73 | var decoder = Base64Decoder(); 74 | 75 | var input = new String.fromCharCodes(bytes); 76 | // decode a Base64 encoded list 77 | var result = decoder.convert(input); 78 | 79 | if (createUint8List) { 80 | return createUint8ListFromList(result); 81 | } 82 | 83 | var output = utf8.decode(result); 84 | 85 | return output; 86 | } 87 | 88 | /// Creates a hash value with md5. 89 | static md5Encode(String input) { 90 | if (input == null) throw new ArgumentError("The input is null"); 91 | 92 | var bytes = utf8.encode(input); // data being hashed 93 | var digest = md5.convert(bytes); 94 | 95 | return digest.toString(); 96 | } 97 | 98 | /// Creates a 16 bit hash value with md5. 99 | static bit16md5Enconde(String input) { 100 | var hash = md5Encode(input); 101 | return hash.substring(8, 24); 102 | } 103 | 104 | /// Returns a cipher text with `DES` algorithm. 105 | @Deprecated("No support for Chinese") 106 | static desEncrypt(String message, String key) { 107 | if (message == null || key == null) 108 | throw new ArgumentError("message or key is null"); 109 | 110 | var blockCipher = DESUtils.BlockCipher(DESUtils.DESEngine(), key); 111 | var ciphertext = blockCipher.encodeB64(message); 112 | 113 | return ciphertext; 114 | } 115 | 116 | /// Returns a decoded text with `DES` algorithm. 117 | @Deprecated("No support for Chinese") 118 | static desDecrypt(String ciphertext, String key) { 119 | if (ciphertext == null || key == null) 120 | throw new ArgumentError("ciphertext or key is null"); 121 | 122 | var blockCipher = DESUtils.BlockCipher(DESUtils.DESEngine(), key); 123 | var decodedText = blockCipher.decodeB64(ciphertext); 124 | 125 | return decodedText; 126 | } 127 | 128 | /// Private. The length for AES key is 128 bits, 192 bits, 256 bits. 129 | static Uint8List _getAESKey(String key, int blockSize) { 130 | var keyData = createUint8ListFromList(utf8.encode(key)); 131 | 132 | var length = blockSize ~/ 8; 133 | var output = createUint8ListFromList(List.generate(length, (i) => 0)); 134 | 135 | int count = Math.min(keyData.lengthInBytes, output.lengthInBytes); 136 | for (var i = 0; i < count; i++) { 137 | output[i] = keyData[i]; 138 | } 139 | 140 | return output; 141 | } 142 | 143 | /// Returns a cipher text with `AES` algorithm. 144 | /// The length for AES key is 128 bits, 192 bits, 256 bits. 145 | static aesEncrypt(String message, String key, {int blockSize: 128}) { 146 | if (message == null || key == null) 147 | throw new ArgumentError("message or key is null"); 148 | 149 | var keyData = _getAESKey(key, blockSize); 150 | var aes = AES.fromBytes(keyData); 151 | var ciphertext = aes.encode(message); 152 | 153 | return ciphertext; 154 | } 155 | 156 | /// Returns a decoded text with `AES` algorithm. 157 | /// The length for AES key is 128 or 192 or 256 bits. 158 | static aesDecrypt(String ciphertext, String key, {int blockSize: 128}) { 159 | if (ciphertext == null || key == null) 160 | throw new ArgumentError("ciphertext or key is null"); 161 | 162 | var keyData = _getAESKey(key, blockSize); 163 | var aes = AES.fromBytes(keyData); 164 | var decryptedText = aes.decode(ciphertext); 165 | 166 | return decryptedText; 167 | } 168 | 169 | /// Returns a cipher text with `RSA` algorithm. 170 | static rsaEncrypt(String message, String publicKey) { 171 | if (message == null || publicKey == null) 172 | throw new ArgumentError("message or publicKey is null"); 173 | 174 | String pubKey = RSAKeyFormatter.formatRSAPublicKey(publicKey); 175 | KeyPair pair = KeyPair.parsePem(pubKey); 176 | int blockSize = pair.bytesize - 11; 177 | 178 | var builder = BytesBuilder(); 179 | 180 | var data = utf8.encode(message); 181 | var rb = RSABlock(data, blockSize); 182 | int count = rb.blockCount; 183 | 184 | for (var i = 0; i < count; i++) { 185 | int dataLength = data.length; 186 | 187 | int start = i * blockSize; 188 | int bufferSize = Math.min(blockSize, dataLength - start); 189 | int end = start + bufferSize; 190 | var subdata = data.sublist(start, end); 191 | 192 | var bytes = pair.encrypt(subdata); 193 | builder.add(bytes); 194 | } 195 | 196 | var ciphertext = base64Encode(builder.toBytes()); 197 | 198 | return ciphertext; 199 | } 200 | 201 | /// Returns a decoded text with `RSA` algorithm. 202 | static rsaDecrypt(String ciphertext, String privateKey) { 203 | if (ciphertext == null || privateKey == null) 204 | throw new ArgumentError("ciphertext or privateKey is null"); 205 | 206 | String privKey = RSAKeyFormatter.formatRSAPrivateKey(privateKey); 207 | KeyPair pair = KeyPair.parsePem(privKey); 208 | int blockSize = pair.bytesize; 209 | 210 | var builder = BytesBuilder(); 211 | 212 | var data = base64Decode(ciphertext); 213 | var rb = RSABlock(data, blockSize); 214 | int count = rb.blockCount; 215 | 216 | for (var i = 0; i < count; i++) { 217 | int dataLength = data.length; 218 | 219 | int start = i * blockSize; 220 | int bufferSize = Math.min(blockSize, dataLength - start); 221 | int end = start + bufferSize; 222 | var subdata = data.sublist(start, end); 223 | 224 | var bytes = pair.decrypt(subdata); 225 | builder.add(bytes); 226 | } 227 | 228 | var decryptedText = utf8.decode(builder.toBytes()); 229 | 230 | return decryptedText; 231 | } 232 | 233 | /// Returns a signature with `RSA` algorithm. 234 | static rsaSign(String message, String privateKey) { 235 | if (message == null || privateKey == null) 236 | throw new ArgumentError("message or privateKey is null"); 237 | 238 | String privKey = RSAKeyFormatter.formatRSAPrivateKey(privateKey); 239 | KeyPair pair = KeyPair.parsePem(privKey); 240 | 241 | var msgBytes = createUint8ListFromList(utf8.encode(message)); 242 | var signBytes = pair.sign(msgBytes); 243 | 244 | var sign = base64Encode(signBytes); 245 | 246 | return sign; 247 | } 248 | 249 | /// Verifies a signature with `RSA` algorithm. 250 | /// If true, the signature is correct, otherwise, signing failed. 251 | static rsaVerify(String signature, String message, String publicKey) { 252 | if (signature == null || message == null || publicKey == null) 253 | throw new ArgumentError("signature, message or publicKey is null"); 254 | 255 | String pubKey = RSAKeyFormatter.formatRSAPublicKey(publicKey); 256 | KeyPair pair = KeyPair.parsePem(pubKey); 257 | 258 | var signBytes = base64Decode(signature); 259 | var msgBytes = createUint8ListFromList(utf8.encode(message)); 260 | bool ret = pair.verify(signBytes, msgBytes); 261 | 262 | return ret; 263 | } 264 | 265 | /// Creates a `Uint8List` by a list of bytes. 266 | static Uint8List createUint8ListFromList(List elements) { 267 | return new Uint8List.fromList(elements); 268 | } 269 | 270 | /// Creates a `Uint8List` by a hex string. 271 | static Uint8List createUint8ListFromHexString(String hex) { 272 | if (hex == null) throw new ArgumentError("hex is null"); 273 | 274 | var result = new Uint8List(hex.length ~/ 2); 275 | for (var i = 0; i < hex.length; i += 2) { 276 | var num = hex.substring(i, i + 2); 277 | var byte = int.parse(num, radix: 16); 278 | result[i ~/ 2] = byte; 279 | } 280 | 281 | return result; 282 | } 283 | 284 | /// Returns a hex string by a `Uint8List`. 285 | static String formatBytesAsHexString(Uint8List bytes) { 286 | if (bytes == null) throw new ArgumentError("The list is null"); 287 | 288 | var result = new StringBuffer(); 289 | for (var i = 0; i < bytes.lengthInBytes; i++) { 290 | var part = bytes[i]; 291 | result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); 292 | } 293 | 294 | return result.toString(); 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /lib/crypto/crypto_rsa.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | // Deprecated("Use rsa keyPair") 6 | // 7 | 8 | import 'dart:convert'; 9 | import 'dart:io'; 10 | import 'dart:math' as Math; 11 | import 'dart:typed_data'; 12 | 13 | import 'package:pointycastle/pointycastle.dart' as pointy; 14 | import 'package:pointycastle/export.dart'; 15 | 16 | import './rsa/rsa_block.dart'; 17 | 18 | class RSAPublicKey { 19 | /// Modulus 20 | final BigInt n; 21 | 22 | /// Public exponent 23 | final BigInt e; 24 | 25 | RSAPublicKey(this.n, this.e); 26 | } 27 | 28 | class RSAPrivateKey implements RSAPublicKey { 29 | /// Modulus 30 | final BigInt n; 31 | 32 | /// Public exponent 33 | final BigInt e; 34 | 35 | /// Private exponent 36 | final BigInt d; 37 | 38 | /// Prime p 39 | final BigInt p; 40 | 41 | /// Prime q 42 | final BigInt q; 43 | 44 | RSAPrivateKey(this.n, this.e, this.d, this.p, this.q); 45 | } 46 | 47 | @Deprecated("Use rsa keyPair") 48 | class RSAEncoder extends Converter { 49 | final RSAPublicKey key; 50 | 51 | RSAEncoder(this.key); 52 | 53 | @override 54 | String convert(String input) { 55 | var engine = RSAEngine(); 56 | engine.reset(); 57 | engine.init( 58 | true, 59 | PublicKeyParameter( 60 | pointy.RSAPublicKey(key.n, key.e))); 61 | 62 | // input.codeUnits 63 | Uint8List data = Uint8List.fromList(utf8.encode(input)); 64 | 65 | int blockSize = engine.inputBlockSize - 11; 66 | var rb = RSABlock(data, blockSize); 67 | var count = rb.blockCount; 68 | 69 | var builder = BytesBuilder(); 70 | 71 | for (var i = 0; i < count; i++) { 72 | int dataLength = data.lengthInBytes; 73 | 74 | int start = i * blockSize; 75 | int bufferSize = Math.min(blockSize, dataLength - start); 76 | int end = start + bufferSize; 77 | var subdata = data.sublist(start, end); 78 | 79 | Uint8List output = engine.process(Uint8List.fromList(subdata)); 80 | builder.add(output); 81 | } 82 | 83 | // hexStringDecoder.convert(output) 84 | return base64Encode(builder.toBytes()); 85 | } 86 | } 87 | 88 | @Deprecated("Use rsa keyPair") 89 | class RSADecoder extends Converter { 90 | final RSAPrivateKey key; 91 | 92 | RSADecoder(this.key); 93 | 94 | @override 95 | String convert(String input) { 96 | var engine = RSAEngine(); 97 | engine.reset(); 98 | engine.init( 99 | false, 100 | PrivateKeyParameter( 101 | pointy.RSAPrivateKey(key.n, key.d, key.p, key.q))); 102 | 103 | // hexStringEncoder.convert(input) 104 | Uint8List data = base64Decode(input); 105 | 106 | int blockSize = engine.inputBlockSize; 107 | var rb = new RSABlock(data, blockSize); 108 | var count = rb.blockCount; 109 | 110 | var builder = BytesBuilder(); 111 | 112 | for (var i = 0; i < count; i++) { 113 | int dataLength = data.lengthInBytes; 114 | 115 | int start = i * blockSize; 116 | int bufferSize = Math.min(blockSize, dataLength - start); 117 | int end = start + bufferSize; 118 | var subdata = data.sublist(start, end); 119 | 120 | Uint8List output = engine.process(Uint8List.fromList(subdata)); 121 | builder.add(output); 122 | } 123 | 124 | return utf8.decode(builder.toBytes()); 125 | } 126 | } 127 | 128 | @Deprecated("Use rsa keyPair") 129 | class RSA extends Codec { 130 | @override 131 | final RSAEncoder encoder; 132 | 133 | @override 134 | final RSADecoder decoder; 135 | 136 | RSA(RSAPublicKey key) 137 | : encoder = RSAEncoder(key), 138 | decoder = key is RSAPrivateKey ? RSADecoder(key) : null; 139 | 140 | @override 141 | String decode(String encoded) { 142 | if (decoder == null) throw Exception('Do not have Private key!'); 143 | return super.decode(encoded); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /lib/crypto/des/src/block_cipher.dart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itenfay/dart_crypto/2ffbc331f09540b82b56ce778d89388688840360/lib/crypto/des/src/block_cipher.dart -------------------------------------------------------------------------------- /lib/crypto/des/src/constants.dart: -------------------------------------------------------------------------------- 1 | // Permuted Choice 1 constants 2 | var PC1 = [ 3 | 57, 4 | 49, 5 | 41, 6 | 33, 7 | 25, 8 | 17, 9 | 9, 10 | 1, 11 | 58, 12 | 50, 13 | 42, 14 | 34, 15 | 26, 16 | 18, 17 | 10, 18 | 2, 19 | 59, 20 | 51, 21 | 43, 22 | 35, 23 | 27, 24 | 19, 25 | 11, 26 | 3, 27 | 60, 28 | 52, 29 | 44, 30 | 36, 31 | 63, 32 | 55, 33 | 47, 34 | 39, 35 | 31, 36 | 23, 37 | 15, 38 | 7, 39 | 62, 40 | 54, 41 | 46, 42 | 38, 43 | 30, 44 | 22, 45 | 14, 46 | 6, 47 | 61, 48 | 53, 49 | 45, 50 | 37, 51 | 29, 52 | 21, 53 | 13, 54 | 5, 55 | 28, 56 | 20, 57 | 12, 58 | 4 59 | ]; 60 | 61 | // Permuted Choice 2 constants 62 | var PC2 = [ 63 | 14, 64 | 17, 65 | 11, 66 | 24, 67 | 1, 68 | 5, 69 | 3, 70 | 28, 71 | 15, 72 | 6, 73 | 21, 74 | 10, 75 | 23, 76 | 19, 77 | 12, 78 | 4, 79 | 26, 80 | 8, 81 | 16, 82 | 7, 83 | 27, 84 | 20, 85 | 13, 86 | 2, 87 | 41, 88 | 52, 89 | 31, 90 | 37, 91 | 47, 92 | 55, 93 | 30, 94 | 40, 95 | 51, 96 | 45, 97 | 33, 98 | 48, 99 | 44, 100 | 49, 101 | 39, 102 | 56, 103 | 34, 104 | 53, 105 | 46, 106 | 42, 107 | 50, 108 | 36, 109 | 29, 110 | 32 111 | ]; 112 | 113 | // Cumulative bit shift constants 114 | var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 115 | 116 | // SBOXes and round permutation constants 117 | var SBOX_P = [ 118 | { 119 | 0x0: 0x808200, 120 | 0x10000000: 0x8000, 121 | 0x20000000: 0x808002, 122 | 0x30000000: 0x2, 123 | 0x40000000: 0x200, 124 | 0x50000000: 0x808202, 125 | 0x60000000: 0x800202, 126 | 0x70000000: 0x800000, 127 | 0x80000000: 0x202, 128 | 0x90000000: 0x800200, 129 | 0xa0000000: 0x8200, 130 | 0xb0000000: 0x808000, 131 | 0xc0000000: 0x8002, 132 | 0xd0000000: 0x800002, 133 | 0xe0000000: 0x0, 134 | 0xf0000000: 0x8202, 135 | 0x8000000: 0x0, 136 | 0x18000000: 0x808202, 137 | 0x28000000: 0x8202, 138 | 0x38000000: 0x8000, 139 | 0x48000000: 0x808200, 140 | 0x58000000: 0x200, 141 | 0x68000000: 0x808002, 142 | 0x78000000: 0x2, 143 | 0x88000000: 0x800200, 144 | 0x98000000: 0x8200, 145 | 0xa8000000: 0x808000, 146 | 0xb8000000: 0x800202, 147 | 0xc8000000: 0x800002, 148 | 0xd8000000: 0x8002, 149 | 0xe8000000: 0x202, 150 | 0xf8000000: 0x800000, 151 | 0x1: 0x8000, 152 | 0x10000001: 0x2, 153 | 0x20000001: 0x808200, 154 | 0x30000001: 0x800000, 155 | 0x40000001: 0x808002, 156 | 0x50000001: 0x8200, 157 | 0x60000001: 0x200, 158 | 0x70000001: 0x800202, 159 | 0x80000001: 0x808202, 160 | 0x90000001: 0x808000, 161 | 0xa0000001: 0x800002, 162 | 0xb0000001: 0x8202, 163 | 0xc0000001: 0x202, 164 | 0xd0000001: 0x800200, 165 | 0xe0000001: 0x8002, 166 | 0xf0000001: 0x0, 167 | 0x8000001: 0x808202, 168 | 0x18000001: 0x808000, 169 | 0x28000001: 0x800000, 170 | 0x38000001: 0x200, 171 | 0x48000001: 0x8000, 172 | 0x58000001: 0x800002, 173 | 0x68000001: 0x2, 174 | 0x78000001: 0x8202, 175 | 0x88000001: 0x8002, 176 | 0x98000001: 0x800202, 177 | 0xa8000001: 0x202, 178 | 0xb8000001: 0x808200, 179 | 0xc8000001: 0x800200, 180 | 0xd8000001: 0x0, 181 | 0xe8000001: 0x8200, 182 | 0xf8000001: 0x808002 183 | }, 184 | { 185 | 0x0: 0x40084010, 186 | 0x1000000: 0x4000, 187 | 0x2000000: 0x80000, 188 | 0x3000000: 0x40080010, 189 | 0x4000000: 0x40000010, 190 | 0x5000000: 0x40084000, 191 | 0x6000000: 0x40004000, 192 | 0x7000000: 0x10, 193 | 0x8000000: 0x84000, 194 | 0x9000000: 0x40004010, 195 | 0xa000000: 0x40000000, 196 | 0xb000000: 0x84010, 197 | 0xc000000: 0x80010, 198 | 0xd000000: 0x0, 199 | 0xe000000: 0x4010, 200 | 0xf000000: 0x40080000, 201 | 0x800000: 0x40004000, 202 | 0x1800000: 0x84010, 203 | 0x2800000: 0x10, 204 | 0x3800000: 0x40004010, 205 | 0x4800000: 0x40084010, 206 | 0x5800000: 0x40000000, 207 | 0x6800000: 0x80000, 208 | 0x7800000: 0x40080010, 209 | 0x8800000: 0x80010, 210 | 0x9800000: 0x0, 211 | 0xa800000: 0x4000, 212 | 0xb800000: 0x40080000, 213 | 0xc800000: 0x40000010, 214 | 0xd800000: 0x84000, 215 | 0xe800000: 0x40084000, 216 | 0xf800000: 0x4010, 217 | 0x10000000: 0x0, 218 | 0x11000000: 0x40080010, 219 | 0x12000000: 0x40004010, 220 | 0x13000000: 0x40084000, 221 | 0x14000000: 0x40080000, 222 | 0x15000000: 0x10, 223 | 0x16000000: 0x84010, 224 | 0x17000000: 0x4000, 225 | 0x18000000: 0x4010, 226 | 0x19000000: 0x80000, 227 | 0x1a000000: 0x80010, 228 | 0x1b000000: 0x40000010, 229 | 0x1c000000: 0x84000, 230 | 0x1d000000: 0x40004000, 231 | 0x1e000000: 0x40000000, 232 | 0x1f000000: 0x40084010, 233 | 0x10800000: 0x84010, 234 | 0x11800000: 0x80000, 235 | 0x12800000: 0x40080000, 236 | 0x13800000: 0x4000, 237 | 0x14800000: 0x40004000, 238 | 0x15800000: 0x40084010, 239 | 0x16800000: 0x10, 240 | 0x17800000: 0x40000000, 241 | 0x18800000: 0x40084000, 242 | 0x19800000: 0x40000010, 243 | 0x1a800000: 0x40004010, 244 | 0x1b800000: 0x80010, 245 | 0x1c800000: 0x0, 246 | 0x1d800000: 0x4010, 247 | 0x1e800000: 0x40080010, 248 | 0x1f800000: 0x84000 249 | }, 250 | { 251 | 0x0: 0x104, 252 | 0x100000: 0x0, 253 | 0x200000: 0x4000100, 254 | 0x300000: 0x10104, 255 | 0x400000: 0x10004, 256 | 0x500000: 0x4000004, 257 | 0x600000: 0x4010104, 258 | 0x700000: 0x4010000, 259 | 0x800000: 0x4000000, 260 | 0x900000: 0x4010100, 261 | 0xa00000: 0x10100, 262 | 0xb00000: 0x4010004, 263 | 0xc00000: 0x4000104, 264 | 0xd00000: 0x10000, 265 | 0xe00000: 0x4, 266 | 0xf00000: 0x100, 267 | 0x80000: 0x4010100, 268 | 0x180000: 0x4010004, 269 | 0x280000: 0x0, 270 | 0x380000: 0x4000100, 271 | 0x480000: 0x4000004, 272 | 0x580000: 0x10000, 273 | 0x680000: 0x10004, 274 | 0x780000: 0x104, 275 | 0x880000: 0x4, 276 | 0x980000: 0x100, 277 | 0xa80000: 0x4010000, 278 | 0xb80000: 0x10104, 279 | 0xc80000: 0x10100, 280 | 0xd80000: 0x4000104, 281 | 0xe80000: 0x4010104, 282 | 0xf80000: 0x4000000, 283 | 0x1000000: 0x4010100, 284 | 0x1100000: 0x10004, 285 | 0x1200000: 0x10000, 286 | 0x1300000: 0x4000100, 287 | 0x1400000: 0x100, 288 | 0x1500000: 0x4010104, 289 | 0x1600000: 0x4000004, 290 | 0x1700000: 0x0, 291 | 0x1800000: 0x4000104, 292 | 0x1900000: 0x4000000, 293 | 0x1a00000: 0x4, 294 | 0x1b00000: 0x10100, 295 | 0x1c00000: 0x4010000, 296 | 0x1d00000: 0x104, 297 | 0x1e00000: 0x10104, 298 | 0x1f00000: 0x4010004, 299 | 0x1080000: 0x4000000, 300 | 0x1180000: 0x104, 301 | 0x1280000: 0x4010100, 302 | 0x1380000: 0x0, 303 | 0x1480000: 0x10004, 304 | 0x1580000: 0x4000100, 305 | 0x1680000: 0x100, 306 | 0x1780000: 0x4010004, 307 | 0x1880000: 0x10000, 308 | 0x1980000: 0x4010104, 309 | 0x1a80000: 0x10104, 310 | 0x1b80000: 0x4000004, 311 | 0x1c80000: 0x4000104, 312 | 0x1d80000: 0x4010000, 313 | 0x1e80000: 0x4, 314 | 0x1f80000: 0x10100 315 | }, 316 | { 317 | 0x0: 0x80401000, 318 | 0x10000: 0x80001040, 319 | 0x20000: 0x401040, 320 | 0x30000: 0x80400000, 321 | 0x40000: 0x0, 322 | 0x50000: 0x401000, 323 | 0x60000: 0x80000040, 324 | 0x70000: 0x400040, 325 | 0x80000: 0x80000000, 326 | 0x90000: 0x400000, 327 | 0xa0000: 0x40, 328 | 0xb0000: 0x80001000, 329 | 0xc0000: 0x80400040, 330 | 0xd0000: 0x1040, 331 | 0xe0000: 0x1000, 332 | 0xf0000: 0x80401040, 333 | 0x8000: 0x80001040, 334 | 0x18000: 0x40, 335 | 0x28000: 0x80400040, 336 | 0x38000: 0x80001000, 337 | 0x48000: 0x401000, 338 | 0x58000: 0x80401040, 339 | 0x68000: 0x0, 340 | 0x78000: 0x80400000, 341 | 0x88000: 0x1000, 342 | 0x98000: 0x80401000, 343 | 0xa8000: 0x400000, 344 | 0xb8000: 0x1040, 345 | 0xc8000: 0x80000000, 346 | 0xd8000: 0x400040, 347 | 0xe8000: 0x401040, 348 | 0xf8000: 0x80000040, 349 | 0x100000: 0x400040, 350 | 0x110000: 0x401000, 351 | 0x120000: 0x80000040, 352 | 0x130000: 0x0, 353 | 0x140000: 0x1040, 354 | 0x150000: 0x80400040, 355 | 0x160000: 0x80401000, 356 | 0x170000: 0x80001040, 357 | 0x180000: 0x80401040, 358 | 0x190000: 0x80000000, 359 | 0x1a0000: 0x80400000, 360 | 0x1b0000: 0x401040, 361 | 0x1c0000: 0x80001000, 362 | 0x1d0000: 0x400000, 363 | 0x1e0000: 0x40, 364 | 0x1f0000: 0x1000, 365 | 0x108000: 0x80400000, 366 | 0x118000: 0x80401040, 367 | 0x128000: 0x0, 368 | 0x138000: 0x401000, 369 | 0x148000: 0x400040, 370 | 0x158000: 0x80000000, 371 | 0x168000: 0x80001040, 372 | 0x178000: 0x40, 373 | 0x188000: 0x80000040, 374 | 0x198000: 0x1000, 375 | 0x1a8000: 0x80001000, 376 | 0x1b8000: 0x80400040, 377 | 0x1c8000: 0x1040, 378 | 0x1d8000: 0x80401000, 379 | 0x1e8000: 0x400000, 380 | 0x1f8000: 0x401040 381 | }, 382 | { 383 | 0x0: 0x80, 384 | 0x1000: 0x1040000, 385 | 0x2000: 0x40000, 386 | 0x3000: 0x20000000, 387 | 0x4000: 0x20040080, 388 | 0x5000: 0x1000080, 389 | 0x6000: 0x21000080, 390 | 0x7000: 0x40080, 391 | 0x8000: 0x1000000, 392 | 0x9000: 0x20040000, 393 | 0xa000: 0x20000080, 394 | 0xb000: 0x21040080, 395 | 0xc000: 0x21040000, 396 | 0xd000: 0x0, 397 | 0xe000: 0x1040080, 398 | 0xf000: 0x21000000, 399 | 0x800: 0x1040080, 400 | 0x1800: 0x21000080, 401 | 0x2800: 0x80, 402 | 0x3800: 0x1040000, 403 | 0x4800: 0x40000, 404 | 0x5800: 0x20040080, 405 | 0x6800: 0x21040000, 406 | 0x7800: 0x20000000, 407 | 0x8800: 0x20040000, 408 | 0x9800: 0x0, 409 | 0xa800: 0x21040080, 410 | 0xb800: 0x1000080, 411 | 0xc800: 0x20000080, 412 | 0xd800: 0x21000000, 413 | 0xe800: 0x1000000, 414 | 0xf800: 0x40080, 415 | 0x10000: 0x40000, 416 | 0x11000: 0x80, 417 | 0x12000: 0x20000000, 418 | 0x13000: 0x21000080, 419 | 0x14000: 0x1000080, 420 | 0x15000: 0x21040000, 421 | 0x16000: 0x20040080, 422 | 0x17000: 0x1000000, 423 | 0x18000: 0x21040080, 424 | 0x19000: 0x21000000, 425 | 0x1a000: 0x1040000, 426 | 0x1b000: 0x20040000, 427 | 0x1c000: 0x40080, 428 | 0x1d000: 0x20000080, 429 | 0x1e000: 0x0, 430 | 0x1f000: 0x1040080, 431 | 0x10800: 0x21000080, 432 | 0x11800: 0x1000000, 433 | 0x12800: 0x1040000, 434 | 0x13800: 0x20040080, 435 | 0x14800: 0x20000000, 436 | 0x15800: 0x1040080, 437 | 0x16800: 0x80, 438 | 0x17800: 0x21040000, 439 | 0x18800: 0x40080, 440 | 0x19800: 0x21040080, 441 | 0x1a800: 0x0, 442 | 0x1b800: 0x21000000, 443 | 0x1c800: 0x1000080, 444 | 0x1d800: 0x40000, 445 | 0x1e800: 0x20040000, 446 | 0x1f800: 0x20000080 447 | }, 448 | { 449 | 0x0: 0x10000008, 450 | 0x100: 0x2000, 451 | 0x200: 0x10200000, 452 | 0x300: 0x10202008, 453 | 0x400: 0x10002000, 454 | 0x500: 0x200000, 455 | 0x600: 0x200008, 456 | 0x700: 0x10000000, 457 | 0x800: 0x0, 458 | 0x900: 0x10002008, 459 | 0xa00: 0x202000, 460 | 0xb00: 0x8, 461 | 0xc00: 0x10200008, 462 | 0xd00: 0x202008, 463 | 0xe00: 0x2008, 464 | 0xf00: 0x10202000, 465 | 0x80: 0x10200000, 466 | 0x180: 0x10202008, 467 | 0x280: 0x8, 468 | 0x380: 0x200000, 469 | 0x480: 0x202008, 470 | 0x580: 0x10000008, 471 | 0x680: 0x10002000, 472 | 0x780: 0x2008, 473 | 0x880: 0x200008, 474 | 0x980: 0x2000, 475 | 0xa80: 0x10002008, 476 | 0xb80: 0x10200008, 477 | 0xc80: 0x0, 478 | 0xd80: 0x10202000, 479 | 0xe80: 0x202000, 480 | 0xf80: 0x10000000, 481 | 0x1000: 0x10002000, 482 | 0x1100: 0x10200008, 483 | 0x1200: 0x10202008, 484 | 0x1300: 0x2008, 485 | 0x1400: 0x200000, 486 | 0x1500: 0x10000000, 487 | 0x1600: 0x10000008, 488 | 0x1700: 0x202000, 489 | 0x1800: 0x202008, 490 | 0x1900: 0x0, 491 | 0x1a00: 0x8, 492 | 0x1b00: 0x10200000, 493 | 0x1c00: 0x2000, 494 | 0x1d00: 0x10002008, 495 | 0x1e00: 0x10202000, 496 | 0x1f00: 0x200008, 497 | 0x1080: 0x8, 498 | 0x1180: 0x202000, 499 | 0x1280: 0x200000, 500 | 0x1380: 0x10000008, 501 | 0x1480: 0x10002000, 502 | 0x1580: 0x2008, 503 | 0x1680: 0x10202008, 504 | 0x1780: 0x10200000, 505 | 0x1880: 0x10202000, 506 | 0x1980: 0x10200008, 507 | 0x1a80: 0x2000, 508 | 0x1b80: 0x202008, 509 | 0x1c80: 0x200008, 510 | 0x1d80: 0x0, 511 | 0x1e80: 0x10000000, 512 | 0x1f80: 0x10002008 513 | }, 514 | { 515 | 0x0: 0x100000, 516 | 0x10: 0x2000401, 517 | 0x20: 0x400, 518 | 0x30: 0x100401, 519 | 0x40: 0x2100401, 520 | 0x50: 0x0, 521 | 0x60: 0x1, 522 | 0x70: 0x2100001, 523 | 0x80: 0x2000400, 524 | 0x90: 0x100001, 525 | 0xa0: 0x2000001, 526 | 0xb0: 0x2100400, 527 | 0xc0: 0x2100000, 528 | 0xd0: 0x401, 529 | 0xe0: 0x100400, 530 | 0xf0: 0x2000000, 531 | 0x8: 0x2100001, 532 | 0x18: 0x0, 533 | 0x28: 0x2000401, 534 | 0x38: 0x2100400, 535 | 0x48: 0x100000, 536 | 0x58: 0x2000001, 537 | 0x68: 0x2000000, 538 | 0x78: 0x401, 539 | 0x88: 0x100401, 540 | 0x98: 0x2000400, 541 | 0xa8: 0x2100000, 542 | 0xb8: 0x100001, 543 | 0xc8: 0x400, 544 | 0xd8: 0x2100401, 545 | 0xe8: 0x1, 546 | 0xf8: 0x100400, 547 | 0x100: 0x2000000, 548 | 0x110: 0x100000, 549 | 0x120: 0x2000401, 550 | 0x130: 0x2100001, 551 | 0x140: 0x100001, 552 | 0x150: 0x2000400, 553 | 0x160: 0x2100400, 554 | 0x170: 0x100401, 555 | 0x180: 0x401, 556 | 0x190: 0x2100401, 557 | 0x1a0: 0x100400, 558 | 0x1b0: 0x1, 559 | 0x1c0: 0x0, 560 | 0x1d0: 0x2100000, 561 | 0x1e0: 0x2000001, 562 | 0x1f0: 0x400, 563 | 0x108: 0x100400, 564 | 0x118: 0x2000401, 565 | 0x128: 0x2100001, 566 | 0x138: 0x1, 567 | 0x148: 0x2000000, 568 | 0x158: 0x100000, 569 | 0x168: 0x401, 570 | 0x178: 0x2100400, 571 | 0x188: 0x2000001, 572 | 0x198: 0x2100000, 573 | 0x1a8: 0x0, 574 | 0x1b8: 0x2100401, 575 | 0x1c8: 0x100401, 576 | 0x1d8: 0x400, 577 | 0x1e8: 0x2000400, 578 | 0x1f8: 0x100001 579 | }, 580 | { 581 | 0x0: 0x8000820, 582 | 0x1: 0x20000, 583 | 0x2: 0x8000000, 584 | 0x3: 0x20, 585 | 0x4: 0x20020, 586 | 0x5: 0x8020820, 587 | 0x6: 0x8020800, 588 | 0x7: 0x800, 589 | 0x8: 0x8020000, 590 | 0x9: 0x8000800, 591 | 0xa: 0x20800, 592 | 0xb: 0x8020020, 593 | 0xc: 0x820, 594 | 0xd: 0x0, 595 | 0xe: 0x8000020, 596 | 0xf: 0x20820, 597 | 0x80000000: 0x800, 598 | 0x80000001: 0x8020820, 599 | 0x80000002: 0x8000820, 600 | 0x80000003: 0x8000000, 601 | 0x80000004: 0x8020000, 602 | 0x80000005: 0x20800, 603 | 0x80000006: 0x20820, 604 | 0x80000007: 0x20, 605 | 0x80000008: 0x8000020, 606 | 0x80000009: 0x820, 607 | 0x8000000a: 0x20020, 608 | 0x8000000b: 0x8020800, 609 | 0x8000000c: 0x0, 610 | 0x8000000d: 0x8020020, 611 | 0x8000000e: 0x8000800, 612 | 0x8000000f: 0x20000, 613 | 0x10: 0x20820, 614 | 0x11: 0x8020800, 615 | 0x12: 0x20, 616 | 0x13: 0x800, 617 | 0x14: 0x8000800, 618 | 0x15: 0x8000020, 619 | 0x16: 0x8020020, 620 | 0x17: 0x20000, 621 | 0x18: 0x0, 622 | 0x19: 0x20020, 623 | 0x1a: 0x8020000, 624 | 0x1b: 0x8000820, 625 | 0x1c: 0x8020820, 626 | 0x1d: 0x20800, 627 | 0x1e: 0x820, 628 | 0x1f: 0x8000000, 629 | 0x80000010: 0x20000, 630 | 0x80000011: 0x800, 631 | 0x80000012: 0x8020020, 632 | 0x80000013: 0x20820, 633 | 0x80000014: 0x20, 634 | 0x80000015: 0x8020000, 635 | 0x80000016: 0x8000000, 636 | 0x80000017: 0x8000820, 637 | 0x80000018: 0x8020820, 638 | 0x80000019: 0x8000020, 639 | 0x8000001a: 0x8000800, 640 | 0x8000001b: 0x0, 641 | 0x8000001c: 0x20800, 642 | 0x8000001d: 0x820, 643 | 0x8000001e: 0x20020, 644 | 0x8000001f: 0x8020800 645 | } 646 | ]; 647 | 648 | // Masks that select the SBOX input 649 | var SBOX_MASK = [ 650 | 0xf8000001, 651 | 0x1f800000, 652 | 0x01f80000, 653 | 0x001f8000, 654 | 0x0001f800, 655 | 0x00001f80, 656 | 0x000001f8, 657 | 0x8000001f 658 | ]; 659 | -------------------------------------------------------------------------------- /lib/crypto/des/src/des.dart: -------------------------------------------------------------------------------- 1 | import '../src/constants.dart'; 2 | import '../src/engine.dart'; 3 | import '../src/utils.dart'; 4 | 5 | class DESEngine extends BaseEngine { 6 | List> _subKeys; 7 | int _lBlock; 8 | int _rBlock; 9 | 10 | String get algorithmName => "DES"; 11 | 12 | int get blockSize => 64 ~/ 32; 13 | 14 | void init(bool forEncryption, List key) { 15 | super.init(forEncryption, key); 16 | 17 | // Select 56 bits according to PC1 18 | var keyBits = new List(56); 19 | for (var i = 0; i < 56; i++) { 20 | var keyBitPos = PC1[i] - 1; 21 | keyBits[i] = (rightShift32( 22 | this.key[rightShift32(keyBitPos, 5)], (31 - keyBitPos % 32))) & 23 | 1; 24 | } 25 | 26 | // Assemble 16 subkeys 27 | var subKeys = this._subKeys = new List>.generate(16, (_) => []); 28 | for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 29 | // Create subkey 30 | var subKey = subKeys[nSubKey] = new List.generate(24, (_) => 0); 31 | 32 | // Shortcut 33 | var bitShift = BIT_SHIFTS[nSubKey]; 34 | 35 | // Select 48 bits according to PC2 36 | for (var i = 0; i < 24; i++) { 37 | // Select from the left 28 key bits 38 | subKey[(i ~/ 6) | 0] |= 39 | leftShift32(keyBits[((PC2[i] - 1) + bitShift) % 28], (31 - i % 6)); 40 | 41 | // Select from the right 28 key bits 42 | subKey[4 + ((i ~/ 6) | 0)] |= leftShift32( 43 | keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)], (31 - i % 6)); 44 | } 45 | 46 | // Since each subkey is applied to an expanded 32-bit input, 47 | // the subkey can be broken into 8 values scaled to 32-bits, 48 | // which allows the key to be used without expansion 49 | subKey[0] = (subKey[0] << 1).toSigned(32) | rightShift32(subKey[0], 31); 50 | for (var i = 1; i < 7; i++) { 51 | subKey[i] = rightShift32(subKey[i], ((i - 1) * 4 + 3)); 52 | } 53 | subKey[7] = (subKey[7] << 5).toSigned(32) | (rightShift32(subKey[7], 27)); 54 | } 55 | } 56 | 57 | int processBlock(List M, int offset) { 58 | List> invSubKeys = new List(16); 59 | if (!forEncryption) { 60 | for (var i = 0; i < 16; i++) { 61 | invSubKeys[i] = _subKeys[15 - i]; 62 | } 63 | } 64 | 65 | List> subKeys = forEncryption ? _subKeys : invSubKeys; 66 | 67 | this._lBlock = M[offset].toSigned(32); 68 | this._rBlock = M[offset + 1].toSigned(32); 69 | // Initial permutation 70 | exchangeLR(4, 0x0f0f0f0f); 71 | exchangeLR(16, 0x0000ffff); 72 | exchangeRL(2, 0x33333333); 73 | exchangeRL(8, 0x00ff00ff); 74 | exchangeLR(1, 0x55555555); 75 | 76 | // Rounds 77 | for (var round = 0; round < 16; round++) { 78 | // Shortcuts 79 | var subKey = subKeys[round]; 80 | var lBlock = this._lBlock; 81 | var rBlock = this._rBlock; 82 | 83 | // Feistel function 84 | var f = 0.toSigned(32); 85 | for (var i = 0; i < 8; i++) { 86 | (f |= (SBOX_P[i][((rBlock ^ subKey[i]).toSigned(32) & SBOX_MASK[i]) 87 | .toUnsigned(32)]) 88 | .toSigned(32)) 89 | .toSigned(32); 90 | } 91 | this._lBlock = rBlock.toSigned(32); 92 | this._rBlock = (lBlock ^ f).toSigned(32); 93 | } 94 | 95 | // Undo swap from last round 96 | var t = this._lBlock; 97 | this._lBlock = this._rBlock; 98 | this._rBlock = t; 99 | 100 | // Final permutation 101 | exchangeLR(1, 0x55555555); 102 | exchangeRL(8, 0x00ff00ff); 103 | exchangeRL(2, 0x33333333); 104 | exchangeLR(16, 0x0000ffff); 105 | exchangeLR(4, 0x0f0f0f0f); 106 | 107 | // Set output 108 | M[offset] = this._lBlock; 109 | M[offset + 1] = this._rBlock; 110 | return blockSize; 111 | } 112 | 113 | void reset() { 114 | forEncryption = false; 115 | this.key = null; 116 | _subKeys = null; 117 | _lBlock = null; 118 | _rBlock = null; 119 | } 120 | 121 | // Swap bits across the left and right words 122 | void exchangeLR(offset, mask) { 123 | var t = 124 | (((rightShift32(this._lBlock, offset)).toSigned(32) ^ this._rBlock) & 125 | mask) 126 | .toSigned(32); 127 | (this._rBlock ^= t).toSigned(32); 128 | this._lBlock ^= (t << offset).toSigned(32); 129 | } 130 | 131 | void exchangeRL(offset, mask) { 132 | var t = 133 | (((rightShift32(this._rBlock, offset)).toSigned(32) ^ this._lBlock) & 134 | mask) 135 | .toSigned(32); 136 | (this._lBlock ^= t).toSigned(32); 137 | this._rBlock ^= (t << offset).toSigned(32); 138 | } 139 | } 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /lib/crypto/des/src/engine.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import '../src/utils.dart'; 3 | 4 | abstract class Engine { 5 | void init(bool forEncryption, List key); 6 | List process(List dataWords); 7 | void reset(); 8 | } 9 | 10 | /// BufferedBlockAlgorithm.process() 11 | abstract class BaseEngine implements Engine { 12 | bool forEncryption; 13 | List key; 14 | 15 | void init(bool forEncryption, List key) { 16 | this.key = key; 17 | this.forEncryption = forEncryption; 18 | } 19 | 20 | void reset() { 21 | key = null; 22 | forEncryption = false; 23 | } 24 | 25 | int processBlock(List M, int offset); 26 | 27 | List process(List dataWords) { 28 | var blockSize = 2; 29 | 30 | if (forEncryption) { 31 | pkcs7Pad(dataWords, blockSize); 32 | } 33 | 34 | var doFlush = false; 35 | var dataSigBytes = dataWords.length; 36 | var blockSizeBytes = blockSize * 4; 37 | var minBufferSize = 0; 38 | 39 | // Count blocks ready 40 | var nBlocksReady = dataSigBytes ~/ blockSizeBytes; 41 | if (doFlush) { 42 | // Round up to include partial blocks 43 | nBlocksReady = nBlocksReady.ceil(); 44 | } else { 45 | // Round down to include only full blocks, 46 | // less the number of blocks that must remain in the buffer 47 | nBlocksReady = max((nBlocksReady | 0) - minBufferSize, 0); 48 | } 49 | 50 | // Count words ready 51 | var nWordsReady = nBlocksReady * blockSize; 52 | 53 | // Count bytes ready 54 | var nBytesReady = min(nWordsReady * 4, dataSigBytes); 55 | 56 | // Process blocks 57 | List processedWords; 58 | if (nWordsReady != 0) { 59 | for (var offset = 0; offset < nWordsReady; offset += blockSize) { 60 | // Perform concrete-algorithm logic 61 | processBlock(dataWords, offset); 62 | } 63 | 64 | // Remove processed words 65 | processedWords = dataWords.getRange(0, nWordsReady).toList(); 66 | dataWords.removeRange(0, nWordsReady); 67 | } 68 | 69 | var result = new List.generate(nBytesReady, (i) { 70 | if (i < processedWords.length) { 71 | return processedWords[i]; 72 | } 73 | return 0; 74 | }); 75 | 76 | if (!forEncryption) { 77 | pkcs7Unpad(result, blockSize); 78 | } 79 | 80 | return result; 81 | } 82 | } -------------------------------------------------------------------------------- /lib/crypto/des/src/tripledes.dart: -------------------------------------------------------------------------------- 1 | import '../src/des.dart'; 2 | import '../src/engine.dart'; 3 | 4 | class TripleDESEngine extends BaseEngine { 5 | String get algorithmName => "TripleDES"; 6 | 7 | int get blockSize => 64 ~/ 32; 8 | 9 | int processBlock(List M, int offset) { 10 | var des1 = new DESEngine(); 11 | var des2 = new DESEngine(); 12 | var des3 = new DESEngine(); 13 | if (forEncryption) { 14 | des1.init(true, key.sublist(0, 2)); 15 | des1.processBlock(M, offset); 16 | des2.init(false, key.sublist(2, 4)); 17 | des2.processBlock(M, offset); 18 | des3.init(true, key.sublist(4, 6)); 19 | des3.processBlock(M, offset); 20 | } else { 21 | des3.init(false, key.sublist(4, 6)); 22 | des3.processBlock(M, offset); 23 | des2.init(true, key.sublist(2, 4)); 24 | des2.processBlock(M, offset); 25 | des1.init(false, key.sublist(0, 2)); 26 | des1.processBlock(M, offset); 27 | } 28 | return blockSize; 29 | } 30 | } -------------------------------------------------------------------------------- /lib/crypto/des/src/utils.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | int rightShift32(int num, int n) { 4 | return ((num & 0xFFFFFFFF) >> n).toSigned(32); 5 | } 6 | 7 | int leftShift32(int num, int n) { 8 | return ((num & 0xFFFFFFFF) << n).toSigned(32); 9 | } 10 | 11 | Uint8List uInt8ListFrom32BitList(List bit32) { 12 | var result = new Uint8List(bit32.length * 4); 13 | for (var i = 0; i < bit32.length; i++) { 14 | for (var j = 0; j < 4; j++) { 15 | result[i * 4 + j] = bit32[i] /*.toSigned(32)*/ >> (j * 8); 16 | } 17 | } 18 | return result; 19 | } 20 | 21 | List bit32ListFromUInt8List(Uint8List bytes) { 22 | var additionalLength = bytes.length % 4 > 0 ? 4 : 0; 23 | var result = 24 | new List.generate(bytes.length ~/ 4 + additionalLength, (_) => 0); 25 | for (var i = 0; i < bytes.length; i++) { 26 | var resultIdx = i ~/ 4; 27 | var bitShiftAmount = (3 - i % 4); 28 | result[resultIdx] |= bytes[i] << bitShiftAmount; 29 | } 30 | for (var i = 0; i < result.length; i++) { 31 | result[i] = result[i] << 24; 32 | } 33 | return result; 34 | } 35 | 36 | void pkcs7Pad(List data, int blockSize) { 37 | var blockSizeBytes = blockSize * 4; 38 | // Count padding bytes 39 | var nPaddingBytes = blockSizeBytes - data.length % blockSizeBytes; 40 | 41 | // Create padding word 42 | var paddingWord = (nPaddingBytes << 24) | 43 | (nPaddingBytes << 16) | 44 | (nPaddingBytes << 8) | 45 | nPaddingBytes; 46 | 47 | // Create padding 48 | var paddingWords = []; 49 | for (var i = 0; i < nPaddingBytes; i += 4) { 50 | paddingWords.add(paddingWord); 51 | } 52 | 53 | var padding = new List.generate(nPaddingBytes, (i) { 54 | if (i < paddingWords.length) { 55 | return paddingWords[i]; 56 | } else { 57 | return 0; 58 | } 59 | }); 60 | 61 | // Add padding 62 | concat(data, padding); 63 | } 64 | 65 | void pkcs7Unpad(List data, int blockSize) { 66 | var sigBytes = data.length; 67 | var nPaddingBytes = data[rightShift32(sigBytes - 1, 2)] & 0xff; 68 | data.length -= nPaddingBytes; 69 | } 70 | 71 | /// wordarray.concat() 72 | concat(List a, List b) { 73 | // Shortcuts 74 | var thisWords = a; 75 | var thatWords = b; 76 | var thisSigBytes = a.length; 77 | var thatSigBytes = b.length; 78 | 79 | // Clamp excess bits 80 | clamp(a); 81 | 82 | // Concat 83 | if (thisSigBytes % 4 != 0) { 84 | // Copy one byte at a time 85 | for (var i = 0; i < thatSigBytes; i++) { 86 | var thatByte = (thatWords[i >> 2] >> (24 - (i % 4) * 8)) & 0xff; 87 | var idx = (thisSigBytes + i) >> 2; 88 | expandList(thisWords, idx + 1); 89 | thisWords[idx] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 90 | } 91 | } else { 92 | // Copy one word at a time 93 | for (var i = 0; i < thatSigBytes; i += 4) { 94 | var idx = (thisSigBytes + i) >> 2; 95 | if (idx >= thisWords.length) { 96 | thisWords.length = idx + 1; 97 | } 98 | thisWords[idx] = thatWords[i >> 2]; 99 | } 100 | } 101 | a.length = thisSigBytes + thatSigBytes; 102 | } 103 | 104 | void expandList(List data, int newLength) { 105 | if (newLength <= data.length) { 106 | return; 107 | } 108 | 109 | // update the length 110 | data.length = newLength; 111 | 112 | // replace any new allocations with 0 113 | for (var i = 0; i < data.length; i++) { 114 | if (data[i] == null) { 115 | data[i] = 0; 116 | } 117 | } 118 | } 119 | 120 | void clamp(List data) { 121 | // Shortcuts 122 | var words = data; 123 | var sigBytes = data.length; 124 | 125 | // Clamp 126 | words[rightShift32(sigBytes, 2)] &= 127 | (0xffffffff << (32 - (sigBytes % 4) * 8)).toSigned(32); 128 | words.length = (sigBytes / 4).ceil(); 129 | } 130 | 131 | // Latin1.parse 132 | List utf8ToWords(String inp) { 133 | var words = new List.generate(inp.length, (_) => 0); 134 | for (var i = 0; i < inp.length; i++) { 135 | words[i >> 2] |= (inp.codeUnitAt(i) & 0xff).toSigned(32) << 136 | (24 - (i % 4) * 8).toSigned(32); 137 | } 138 | return words; 139 | } 140 | 141 | // Latin1.stringify 142 | String wordsToUtf8(List words) { 143 | var sigBytes = words.length; 144 | var chars = []; 145 | for (var i = 0; i < sigBytes; i++) { 146 | if (words[i >> 2] == null) { 147 | words[i >> 2] = 0; 148 | } 149 | var bite = ((words[i >> 2]).toSigned(32) >> (24 - (i % 4) * 8)) & 0xff; 150 | chars.add(bite); 151 | } 152 | 153 | return new String.fromCharCodes(chars); 154 | } 155 | 156 | List parseBase64(String base64Str) { 157 | const map = 158 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; 159 | List reverseMap; 160 | // Shortcuts 161 | var base64StrLength = base64Str.length; 162 | 163 | if (reverseMap == null) { 164 | reverseMap = new List(123); 165 | for (var j = 0; j < map.length; j++) { 166 | reverseMap[map.codeUnits[j]] = j; 167 | } 168 | } 169 | 170 | // Ignore padding 171 | var paddingChar = map.codeUnits[64]; 172 | if (paddingChar != null) { 173 | var paddingIndex = base64Str.codeUnits.indexOf(paddingChar); 174 | if (paddingIndex != -1) { 175 | base64StrLength = paddingIndex; 176 | } 177 | } 178 | 179 | List parseLoop( 180 | String base64Str, int base64StrLength, List reverseMap) { 181 | var words = []; 182 | var nBytes = 0; 183 | for (var i = 0; i < base64StrLength; i++) { 184 | if (i % 4 != 0) { 185 | var bits1 = reverseMap[base64Str.codeUnits[i - 1]] << 186 | ((i % 4) * 2).toSigned(32); 187 | var bits2 = 188 | rightShift32(reverseMap[base64Str.codeUnits[i]], (6 - (i % 4) * 2)) 189 | .toSigned(32); 190 | var idx = rightShift32(nBytes, 2); 191 | if (words.length <= idx) { 192 | words.length = idx + 1; 193 | } 194 | for (var i = 0; i < words.length; i++) { 195 | if (words[i] == null) words[i] = 0; 196 | } 197 | words[idx] |= ((bits1 | bits2) << (24 - (nBytes % 4) * 8)).toSigned(32); 198 | nBytes++; 199 | } 200 | } 201 | return new List.generate( 202 | nBytes, (i) => i < words.length ? words[i] : 0); 203 | } 204 | 205 | // Convert 206 | return parseLoop(base64Str, base64StrLength, reverseMap); 207 | } 208 | -------------------------------------------------------------------------------- /lib/crypto/des/tripledes.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'src/utils.dart'; 3 | import 'src/engine.dart'; 4 | 5 | export 'src/engine.dart'; 6 | export 'src/des.dart'; 7 | export 'src/tripledes.dart'; 8 | 9 | class BlockCipher { 10 | final Engine engine; 11 | final String key; 12 | 13 | BlockCipher(this.engine, this.key); 14 | 15 | String encode(String message) { 16 | engine.init(true, utf8ToWords(key)); 17 | var result = engine.process(utf8ToWords(message)); 18 | engine.reset(); 19 | return wordsToUtf8(result); 20 | } 21 | 22 | String decode(String ciphertext) { 23 | var b = engine..init(false, utf8ToWords(key)); 24 | var r = b.process(utf8ToWords(ciphertext)); 25 | engine.reset(); 26 | return wordsToUtf8(r); 27 | } 28 | 29 | String encodeB64(String message) { 30 | return base64.encode(encode(message).codeUnits); 31 | } 32 | 33 | String decodeB64(String ciphertext) { 34 | var b = engine..init(false, utf8ToWords(key)); 35 | var result = b.process(parseBase64(ciphertext)); 36 | engine.reset(); 37 | return wordsToUtf8(result); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/crypto/rsa/rsa.dart: -------------------------------------------------------------------------------- 1 | export 'src/rsa_keypair.dart'; 2 | export 'src/rsa_tools.dart'; 3 | export 'src/rsa_padding.dart'; 4 | export 'src/rsa_math.dart'; 5 | export 'src/rsa_key.dart'; 6 | export 'src/rsa_pkcs1.dart'; 7 | export 'src/rsa_hashing.dart'; -------------------------------------------------------------------------------- /lib/crypto/rsa/rsa_block.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | // Calculates the number of block processing times. 7 | class RSABlock { 8 | final data; 9 | final int size; 10 | 11 | RSABlock(this.data, this.size); 12 | 13 | get source => data; 14 | get blockSize => size; 15 | 16 | get blockCount { 17 | int dataLength = data.length; 18 | 19 | var result = dataLength / size; 20 | var count = dataLength ~/ size; 21 | 22 | if (result > count) { 23 | count += 1; 24 | } 25 | 26 | return count; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/crypto/rsa/rsa_key_formatter.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | // Converts the key to the content of pem for RSA 7 | class RSAKeyFormatter { 8 | static formatRSAPublicKey(String publicKey) { 9 | if (publicKey == null) return null; 10 | 11 | var buffer = new StringBuffer(); 12 | buffer.write("-----BEGIN PUBLIC KEY-----\n"); 13 | 14 | final length = publicKey.length; 15 | int count = 0; 16 | 17 | for (var i = 0; i < length; i++) { 18 | var c = publicKey.codeUnitAt(i); 19 | var s = String.fromCharCode(c); 20 | if (s == "\n" || s == "\r") { 21 | continue; 22 | } 23 | buffer.writeCharCode(c); 24 | if (++count == 64) { 25 | buffer.write("\n"); 26 | count = 0; 27 | } 28 | } 29 | 30 | buffer.write("\n-----END PUBLIC KEY-----\n"); 31 | 32 | return buffer.toString(); 33 | } 34 | 35 | static formatRSAPrivateKey(String privateKey) { 36 | if (privateKey == null) return null; 37 | 38 | var buffer = new StringBuffer(); 39 | buffer.write("-----BEGIN PRIVATE KEY-----\n"); 40 | 41 | final length = privateKey.length; 42 | int count = 0; 43 | 44 | for (var i = 0; i < length; i++) { 45 | var c = privateKey.codeUnitAt(i); 46 | var s = String.fromCharCode(c); 47 | if (s == "\n" || s == "\r") { 48 | continue; 49 | } 50 | buffer.writeCharCode(c); 51 | if (++count == 64) { 52 | buffer.write("\n"); 53 | count = 0; 54 | } 55 | } 56 | 57 | buffer.write("\n-----END PRIVATE KEY-----\n"); 58 | 59 | return buffer.toString(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lib/crypto/rsa/src/rsa_hashing.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Modified by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'dart:typed_data' show Uint8List; 7 | import 'dart:math' show max; 8 | 9 | import 'package:crypto/crypto.dart' as crypto; 10 | 11 | const MD5Hash MD5 = const MD5Hash(); 12 | const SHA1Hash SHA1 = const SHA1Hash(); 13 | const SHA256Hash SHA256 = const SHA256Hash(); 14 | 15 | const Map, HashFunction> HASHES = const { 16 | MD5Hash.ASN1CODE: MD5, 17 | SHA1Hash.ASN1CODE: SHA1, 18 | SHA256Hash.ASN1CODE: SHA256 19 | }; 20 | 21 | abstract class HashFunction { 22 | List get asn1code; 23 | List hash(List data); 24 | 25 | const HashFunction(); 26 | 27 | List digestInfo(Uint8List data) { 28 | // var info = []..addAll(asn1code)..addAll(hash(data)); //throws exception with this type. 29 | List info = new List(); 30 | 31 | info.addAll(asn1code); 32 | info.addAll(hash(data)); 33 | 34 | return info; 35 | } 36 | } 37 | 38 | class MD5Hash extends HashFunction { 39 | static const List ASN1CODE = const [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 40 | 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 41 | 0x02, 0x05, 0x05, 0x00, 0x04, 0x10]; 42 | 43 | List get asn1code => ASN1CODE; 44 | 45 | const MD5Hash(); 46 | 47 | List hash(List data) { 48 | var md5 = crypto.md5; 49 | var digest = md5.convert(data); 50 | return digest.bytes; 51 | } 52 | } 53 | 54 | class SHA1Hash extends HashFunction { 55 | static const List ASN1CODE = const [0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 56 | 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 57 | 0x00, 0x04, 0x14]; 58 | 59 | List get asn1code => ASN1CODE; 60 | 61 | const SHA1Hash(); 62 | 63 | List hash(List data) { 64 | var sha1 = crypto.sha1; 65 | var digest = sha1.convert(data); 66 | return digest.bytes; 67 | } 68 | } 69 | 70 | class SHA256Hash extends HashFunction { 71 | static const List ASN1CODE = const [0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 72 | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 73 | 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 74 | 0x20]; 75 | 76 | List get asn1code => ASN1CODE; 77 | 78 | const SHA256Hash(); 79 | 80 | List hash(List data) { 81 | var sha256 = crypto.sha256; 82 | var digest = sha256.convert(data); 83 | return digest.bytes; 84 | } 85 | } 86 | 87 | Uint8List emsaEncode(Uint8List data, int targetLength, 88 | {HashFunction hashFunction: SHA256}) { 89 | var t = hashFunction.digestInfo(data); 90 | if (targetLength < t.length + 11) 91 | throw new ArgumentError.value(targetLength); 92 | var ps = new List.filled(max(targetLength - t.length - 3, 8), 0xff); 93 | var em = [0x00, 0x01]..addAll(ps)..add(0x00)..addAll(t); 94 | return new Uint8List.fromList(em); 95 | } 96 | 97 | bool startsWith(List list, List check) { 98 | for (int i = 0; i < check.length; i++) { 99 | if (list[i] != check[i]) return false; 100 | } 101 | return true; 102 | } 103 | -------------------------------------------------------------------------------- /lib/crypto/rsa/src/rsa_key.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' show Point; 2 | 3 | import '../../rsa_pkcs/rsa_pkcs.dart' show RSAPublicKey, RSAPrivateKey; 4 | 5 | class Key { 6 | final BigInt modulus; 7 | final BigInt exponent; 8 | 9 | Key(this.modulus, this.exponent); 10 | 11 | Key.fromRSAPublicKey(RSAPublicKey pubKey) 12 | : modulus = pubKey.modulus, 13 | exponent = pubKey.publicExponent; 14 | 15 | Key.fromRSAPrivateKey(RSAPrivateKey privKey) 16 | : modulus = privKey.modulus, 17 | exponent = privKey.privateExponent; 18 | 19 | BigInt get n => modulus; 20 | BigInt get e => exponent; 21 | BigInt get d => exponent; 22 | 23 | bool get valid => true; // TODO: Validity checking 24 | 25 | int get modulusBytesize => modulus.bitLength ~/ 8; 26 | 27 | Point toPoint() => new Point(modulus.toInt(), exponent.toInt()); 28 | } 29 | -------------------------------------------------------------------------------- /lib/crypto/rsa/src/rsa_keypair.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data' show Uint8List; 2 | import 'dart:convert' show utf8, latin1; 3 | 4 | import 'rsa_key.dart'; 5 | import 'rsa_pkcs1.dart' as PKCS1; 6 | import 'rsa_padding.dart'; 7 | import 'rsa_tools.dart'; 8 | import 'rsa_hashing.dart'; 9 | 10 | import '../../rsa_pkcs/rsa_pkcs.dart' show RSAPKCSParser; 11 | 12 | class KeyPair { 13 | final Key privateKey; 14 | final Key publicKey; 15 | 16 | Key get private => privateKey; 17 | Key get public => publicKey; 18 | 19 | KeyPair(this.privateKey, this.publicKey); 20 | 21 | static KeyPair parsePem(String pem, [String password]) { 22 | var parser = new RSAPKCSParser(); 23 | var pair = parser.parsePEM(pem, password: password); 24 | var private; 25 | var public; 26 | if (null != pair.private) private = new Key.fromRSAPrivateKey(pair.private); 27 | if (null != pair.public) public = new Key.fromRSAPublicKey(pair.public); 28 | return new KeyPair(private, public); 29 | } 30 | 31 | bool get hasPrivateKey => null != privateKey; 32 | bool get hasPublicKey => null != publicKey; 33 | 34 | BigInt get modulus => 35 | null != privateKey ? privateKey.modulus : publicKey.modulus; 36 | BigInt get n => modulus; 37 | 38 | bool get valid => privateKey.valid && publicKey.valid; 39 | 40 | int get bytesize => modulus.bitLength ~/ 8; 41 | 42 | int get bitsize => modulus.bitLength; 43 | int get size => bitsize; 44 | 45 | encrypt(plainText, {Padding padding: PKCS1_PADDING}) { 46 | if (plainText is String) { 47 | plainText = new Uint8List.fromList(latin1.encode(plainText)); 48 | return DSC.encode(_encrypt(plainText, padding)); 49 | } 50 | if (plainText is Uint8List) return _encrypt(plainText, padding); 51 | throw new ArgumentError.value(plainText); 52 | } 53 | 54 | PublicEncryptionResult publicEncrypt(plainText, 55 | {Padding padding: PKCS1_PADDING, HashFunction hashFunction: SHA256}) { 56 | var encrypted = encrypt(plainText); 57 | var signature = sign(encrypted); 58 | return new PublicEncryptionResult(encrypted, signature); 59 | } 60 | 61 | privateDecrypt(PublicEncryptionResult result, 62 | {Padding padding: PKCS1_PADDING, HashFunction hashFunction: SHA256}) { 63 | if (verify(result.signature, result.cipher, hashFunction: hashFunction)) { 64 | return decrypt(result.cipher, padding: padding); 65 | } 66 | throw new ArgumentError("Signature could not be verified"); 67 | } 68 | 69 | Uint8List _encrypt(Uint8List plainText, padding) { 70 | if (null != padding) plainText = padding.apply(plainText, bytesize); 71 | return PKCS1.i2osp(_encryptInteger(PKCS1.os2ip(plainText)), bytesize); 72 | } 73 | 74 | decrypt(cipherText, {Padding padding: PKCS1_PADDING}) { 75 | if (cipherText is String) { 76 | cipherText = DSC.decode(cipherText); 77 | return new String.fromCharCodes(_decrypt(cipherText, padding)); 78 | } 79 | if (cipherText is Uint8List) return _decrypt(cipherText, padding); 80 | throw new ArgumentError.value(cipherText); 81 | } 82 | 83 | Uint8List _decrypt(Uint8List cipherText, padding) { 84 | cipherText = 85 | PKCS1.i2osp(_decryptInteger(PKCS1.os2ip(cipherText)), bytesize); 86 | if (null != padding) cipherText = padding.strip(cipherText); 87 | return cipherText; 88 | } 89 | 90 | sign(message, {HashFunction hashFunction: SHA256}) { 91 | if (message is String) { 92 | message = DSC.decode(message); 93 | var signature = _sign(message, hashFunction: hashFunction); 94 | return DSC.encode(signature); 95 | } 96 | if (message is Uint8List) return _sign(message, hashFunction: hashFunction); 97 | throw new ArgumentError.value(message); 98 | } 99 | 100 | Uint8List _sign(Uint8List message, {HashFunction hashFunction: SHA256}) { 101 | var em = emsaEncode(message, bytesize, hashFunction: hashFunction); 102 | var m = PKCS1.os2ip(em); 103 | var s = PKCS1.rsasp1(privateKey, m); 104 | var signature = PKCS1.i2osp(s, bytesize); 105 | return signature; 106 | } 107 | 108 | bool verify(signature, message, {HashFunction hashFunction: SHA256}) { 109 | if (signature is String) signature = DSC.decode(signature); 110 | if (message is String) message = DSC.decode(message); 111 | if (signature is! Uint8List) throw new ArgumentError.value(signature); 112 | if (message is! Uint8List) throw new ArgumentError.value(message); 113 | return _verify(signature, message, hashFunction: hashFunction); 114 | } 115 | 116 | bool _verify(Uint8List signature, Uint8List message, 117 | {HashFunction hashFunction: SHA256}) { 118 | if (signature.length != bytesize) throw new ArgumentError.value(signature); 119 | var s = PKCS1.os2ip(signature); 120 | var m = PKCS1.rsavp1(publicKey, s); 121 | var em1 = PKCS1.i2osp(m, bytesize); 122 | var em2 = emsaEncode(message, bytesize); 123 | return equalLists(em1, em2); 124 | } 125 | 126 | bool equalLists(List first, List second) { 127 | if (first.length != second.length) return false; 128 | for (int i = 0; i < first.length; i++) { 129 | if (first[i] != second[i]) { 130 | return false; 131 | } 132 | } 133 | return true; 134 | } 135 | 136 | BigInt _encryptInteger(BigInt plainText) => PKCS1.rsaep(publicKey, plainText); 137 | 138 | BigInt _decryptInteger(BigInt cipherText) => PKCS1.rsadp(privateKey, cipherText); 139 | 140 | BigInt _signInteger(BigInt plainText) => PKCS1.rsasp1(privateKey, plainText); 141 | } 142 | -------------------------------------------------------------------------------- /lib/crypto/rsa/src/rsa_math.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as Math; 2 | 3 | double log2(int number) => logn(number, 2); 4 | 5 | double log256(int number) => logn(number, 256); 6 | 7 | double logn(int number, int base) { 8 | var upper = Math.log(number); 9 | var lower = Math.log(base); 10 | return upper / lower; 11 | } 12 | 13 | int gcd(int a, int b) { 14 | a = a.abs(); 15 | b = b.abs(); 16 | if (b > a) { 17 | var temp = a; 18 | a = b; 19 | b = temp; 20 | } 21 | while (true) { 22 | a %= b; 23 | if (0 == a) return b; 24 | b %= a; 25 | if (b == 0) return a; 26 | } 27 | } 28 | 29 | int modPow(int base, int exponent, int modulus) { 30 | var result = 1; 31 | while (exponent > 0) { 32 | if ((exponent & 1) != 0) result = (base * result) % modulus; 33 | base = (base * base) % modulus; 34 | exponent >>= 1; 35 | } 36 | return result; 37 | } 38 | 39 | Math.Point egcd(int a, int b) { 40 | if (0 == a % b) return new Math.Point(0, 1); 41 | var p = egcd(b, a % b); 42 | return new Math.Point(p.y, p.x - p.y * (a / b)); 43 | } 44 | -------------------------------------------------------------------------------- /lib/crypto/rsa/src/rsa_padding.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' show max, Random; 2 | import 'dart:typed_data' show Uint8List; 3 | 4 | import '../../bbs/bbs.dart' show BlumBlumShub; 5 | 6 | const PKCS1Padding PKCS1_PADDING = const PKCS1Padding(); 7 | 8 | abstract class Padding { 9 | Uint8List apply(Uint8List input, int k); 10 | 11 | Uint8List strip(Uint8List padded); 12 | } 13 | 14 | class PKCS1Padding implements Padding { 15 | const PKCS1Padding(); 16 | 17 | Uint8List apply(Uint8List input, int k) { 18 | var octets = randomOctets(k - input.length - 3); 19 | var padded = [0x00, 0x02]..addAll(octets) 20 | ..add(0x00) 21 | ..addAll(input); 22 | return new Uint8List.fromList(padded); 23 | } 24 | 25 | Uint8List strip(Uint8List bytes) { 26 | if (!_isValidSequence(bytes)) 27 | throw new ArgumentError.value(bytes); 28 | var start = bytes.indexOf(0x00, 2); 29 | var m = bytes.sublist(start + 1); 30 | return m; 31 | } 32 | 33 | bool _isValidSequence(Uint8List bytes) { 34 | if (bytes[0] != 0x00) return false; 35 | if (bytes[1] != 0x02) return false; 36 | var index = bytes.indexOf(0x00, 2); 37 | if (-1 == index) return false; 38 | var ps = bytes.sublist(2, index); 39 | if (8 > ps.length) return false; 40 | return true; 41 | } 42 | 43 | List randomOctets(int length, {Random random}) { 44 | if (null == random) random = new BlumBlumShub(); 45 | length = max(8, length); 46 | var octets = new List.generate(length, (_) => random.nextInt(254) + 1); 47 | return octets; 48 | } 49 | } -------------------------------------------------------------------------------- /lib/crypto/rsa/src/rsa_pkcs1.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' show pow, max; 2 | import 'dart:typed_data' show Uint8List; 3 | 4 | import 'rsa_key.dart'; 5 | 6 | int _bigIntToInt(BigInt big) { 7 | return big.toInt(); 8 | } 9 | 10 | Uint8List i2osp(BigInt x, int len) { 11 | if (null != len && x >= new BigInt.from(256).pow(len)) 12 | throw new ArgumentError("integer too large"); 13 | 14 | var b; 15 | var buffer = new List(); 16 | while (x > new BigInt.from(0)) { 17 | b = x & (new BigInt.from(0xFF)); 18 | x = x >> 8; 19 | buffer.add(_bigIntToInt(b)); 20 | } 21 | 22 | var difference = max(0, len - buffer.length); 23 | buffer.addAll(new List.filled(difference, 0)); 24 | buffer = buffer.reversed.toList(); 25 | return new Uint8List.fromList(buffer); 26 | } 27 | 28 | BigInt os2ip(Uint8List x) { 29 | return x.fold(new BigInt.from(0), (BigInt n, b) => (n << 8) + new BigInt.from(b)); 30 | } 31 | 32 | BigInt rsaep(Key k, BigInt m) { 33 | if (m < new BigInt.from(0) || m >= k.n) 34 | throw new ArgumentError("message representative out of range"); 35 | var c = m.modPow(k.e, k.n); 36 | return c; 37 | } 38 | 39 | BigInt rsadp(Key k, BigInt c) { 40 | if (c < new BigInt.from(0) || c >= k.n) 41 | throw new ArgumentError("ciphertext representative out of range"); 42 | var s = c.modPow(k.d, k.n); 43 | return s; 44 | } 45 | 46 | BigInt rsasp1(Key k, BigInt m) { 47 | if (m < new BigInt.from(0) || m >= k.n) 48 | throw new ArgumentError("message representative out of range"); 49 | var s = m.modPow(k.d, k.n); 50 | return s; 51 | } 52 | 53 | BigInt rsavp1(Key k, BigInt s) { 54 | if (s < new BigInt.from(0) || s >= k.n) 55 | throw new ArgumentError("signature representative out of range"); 56 | var m = s.modPow(k.e, k.n); 57 | return m; 58 | } 59 | -------------------------------------------------------------------------------- /lib/crypto/rsa/src/rsa_tools.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:typed_data' show Uint8List; 3 | 4 | const DigestStringCodec DSC = const DigestStringCodec(); 5 | 6 | class DigestToStringConverter extends Converter { 7 | const DigestToStringConverter() : super(); 8 | 9 | String convert(Uint8List digest) { 10 | var base64 = base64Encode(digest); 11 | var utf = utf8.encode(base64); 12 | return new String.fromCharCodes(utf); 13 | } 14 | } 15 | 16 | class StringToDigestConverter extends Converter { 17 | const StringToDigestConverter() : super(); 18 | 19 | Uint8List convert(String digest) { 20 | var base64 = utf8.decode(digest.codeUnits); 21 | var bytes = base64Decode(base64); 22 | return bytes; 23 | } 24 | } 25 | 26 | class DigestStringCodec extends Codec { 27 | final encoder = const DigestToStringConverter(); 28 | final decoder = const StringToDigestConverter(); 29 | 30 | const DigestStringCodec() : super(); 31 | } 32 | 33 | class PublicEncryptionResult { 34 | final signature; 35 | final cipher; 36 | 37 | PublicEncryptionResult(this.cipher, this.signature); 38 | } 39 | -------------------------------------------------------------------------------- /lib/crypto/rsa_pkcs/rsa_pkcs.dart: -------------------------------------------------------------------------------- 1 | export 'src/parser.dart'; -------------------------------------------------------------------------------- /lib/crypto/rsa_pkcs/src/parser.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Modified by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'dart:convert'; 7 | import 'package:asn1lib/asn1lib.dart'; 8 | 9 | class RSAPKCSParser { 10 | static const String PKCS_HEADER = "-----"; 11 | static const String PKCS1_PUBLIC_HEADER = "-----BEGIN RSA PUBLIC KEY-----"; 12 | static const String PKCS8_PUBLIC_HEADER = "-----BEGIN PUBLIC KEY-----"; 13 | static const String PKCS1_PUBLIC_FOOTER = "-----END RSA PUBLIC KEY-----"; 14 | static const String PKCS8_PUBLIC_FOOTER = "-----END PUBLIC KEY-----"; 15 | 16 | static const String PKCS1_PRIVATE_HEADER = "-----BEGIN RSA PRIVATE KEY-----"; 17 | static const String PKCS8_PRIVATE_HEADER = "-----BEGIN PRIVATE KEY-----"; 18 | static const String PKCS1_PRIVATE_FOOTER = "-----END RSA PRIVATE KEY-----"; 19 | static const String PKCS8_PRIVATE_FOOTER = "-----END PRIVATE KEY-----"; 20 | 21 | static const String PKCS8_PRIVATE_ENC_HEADER = 22 | "-----BEGIN ENCRYPTED PRIVATE KEY-----"; 23 | static const String PKCS8_PRIVATE_ENC_FOOTER = 24 | "-----END ENCRYPTED PRIVATE KEY-----"; 25 | 26 | RSAKeyPair parsePEM(String pem, {String password}) { 27 | List lines = pem 28 | .split("\n") 29 | .map((line) => line.trim()) 30 | .where((line) => line.isNotEmpty) 31 | .skipWhile((String line) => !line.startsWith(PKCS_HEADER)) 32 | .toList(); 33 | if (lines.isEmpty) this._error("format error"); 34 | return new RSAKeyPair(_publicKey(lines), _privateKey(lines)); 35 | } 36 | 37 | RSAPrivateKey _privateKey(List lines, {String password}) { 38 | var header = lines.indexOf(PKCS1_PRIVATE_HEADER); 39 | 40 | var footer; 41 | if (header >= 0) { 42 | footer = lines.indexOf(PKCS1_PRIVATE_FOOTER); 43 | } else if ((header = lines.indexOf(PKCS8_PRIVATE_HEADER)) >= 0) { 44 | footer = lines.indexOf(PKCS8_PRIVATE_FOOTER); 45 | } else if ((header = lines.indexOf(PKCS8_PRIVATE_ENC_HEADER)) >= 0) { 46 | footer = lines.indexOf(PKCS8_PRIVATE_ENC_FOOTER); 47 | } else 48 | return null; 49 | if (footer < 0) this._error("format error : cannot find footer"); 50 | 51 | var key = lines.sublist(header + 1, footer).join(""); 52 | var keyBytes = base64.decode(key); 53 | var p = new ASN1Parser(keyBytes); 54 | 55 | ASN1Sequence seq = p.nextObject(); 56 | 57 | if (lines[header] == PKCS1_PRIVATE_HEADER) 58 | return _pkcs1PrivateKey(seq); 59 | else if (lines[header] == PKCS8_PRIVATE_HEADER) 60 | return _pkcs8PrivateKey(seq); 61 | else 62 | return _pkcs8PrivateEncKey(seq, password); 63 | } 64 | 65 | RSAPrivateKey _pkcs8PrivateEncKey(ASN1Sequence seq, String password) { 66 | throw new UnimplementedError(); 67 | // ASN1OctetString asnkey = (seq.elements[0] as ASN1Sequence).elements[2]; 68 | // var bytes = asnkey.valueBytes(); 69 | // final key = new Uint8List.fromList([ 70 | // 0x00, 71 | // 0x11, 72 | // 0x22, 73 | // 0x33, 74 | // 0x44, 75 | // 0x55, 76 | // 0x66, 77 | // 0x77, 78 | // 0x88, 79 | // 0x99, 80 | // 0xAA, 81 | // 0xBB, 82 | // 0xCC, 83 | // 0xDD, 84 | // 0xEE, 85 | // 0xFF 86 | // ]); 87 | // final params = new KeyParameter(key); 88 | // BlockCipher bc = new BlockCipher("AES"); 89 | 90 | // return null; 91 | } 92 | 93 | RSAPrivateKey _pkcs1PrivateKey(ASN1Sequence seq) { 94 | RSAPrivateKey key = new RSAPrivateKey(); 95 | key.version = (seq.elements[0] as ASN1Integer).intValue; 96 | key.modulus = (seq.elements[1] as ASN1Integer).valueAsBigInteger; 97 | key.publicExponent = (seq.elements[2] as ASN1Integer).valueAsBigInteger; 98 | key.privateExponent = (seq.elements[3] as ASN1Integer).valueAsBigInteger; 99 | key.prime1 = (seq.elements[4] as ASN1Integer).valueAsBigInteger; 100 | key.prime2 = (seq.elements[5] as ASN1Integer).valueAsBigInteger; 101 | key.exponent1 = (seq.elements[6] as ASN1Integer).valueAsBigInteger; 102 | key.exponent2 = (seq.elements[7] as ASN1Integer).valueAsBigInteger; 103 | key.coefficient = (seq.elements[8] as ASN1Integer).valueAsBigInteger; 104 | return key; 105 | } 106 | 107 | RSAPrivateKey _pkcs8PrivateKey(ASN1Sequence seq) { 108 | ASN1OctetString os = seq.elements[2]; 109 | ASN1Parser p = new ASN1Parser(os.valueBytes()); 110 | return _pkcs1PrivateKey(p.nextObject()); 111 | } 112 | 113 | RSAPublicKey _publicKey(List lines) { 114 | var header = lines.indexOf(PKCS1_PUBLIC_HEADER); 115 | var footer; 116 | if (header >= 0) { 117 | footer = lines.indexOf(PKCS1_PUBLIC_FOOTER); 118 | } else if ((header = lines.indexOf(PKCS8_PUBLIC_HEADER)) >= 0) { 119 | footer = lines.indexOf(PKCS8_PUBLIC_FOOTER); 120 | } else 121 | return null; 122 | if (footer < 0) this._error("format error : cannot find footer"); 123 | 124 | var key = lines.sublist(header + 1, footer).join(""); 125 | var keyBytes = base64.decode(key); 126 | var p = new ASN1Parser(keyBytes); 127 | 128 | ASN1Sequence seq = p.nextObject(); 129 | 130 | if (lines[header] == PKCS1_PUBLIC_HEADER) 131 | return _pkcs1PublicKey(seq); 132 | else 133 | return _pkcs8PublicKey(seq); 134 | } 135 | 136 | RSAPublicKey _pkcs1PublicKey(ASN1Sequence seq) { 137 | RSAPublicKey key = new RSAPublicKey(); 138 | key.modulus = (seq.elements[0] as ASN1Integer).valueAsBigInteger; 139 | key.publicExponent = (seq.elements[1] as ASN1Integer).valueAsBigInteger; 140 | return key; 141 | } 142 | 143 | RSAPublicKey _pkcs8PublicKey(ASN1Sequence seq) { 144 | ASN1BitString os = seq.elements[1]; //ASN1OctetString or ASN1BitString 145 | var bytes = os.valueBytes().sublist(1); 146 | ASN1Parser p = new ASN1Parser(bytes); 147 | return _pkcs1PublicKey(p.nextObject()); 148 | } 149 | 150 | void _error(String msg) { 151 | throw "${this.runtimeType} : $msg"; 152 | } 153 | } 154 | 155 | class RSAKeyPair { 156 | RSAPublicKey public; 157 | RSAPrivateKey private; 158 | 159 | RSAKeyPair(this.public, this.private); 160 | } 161 | 162 | class RSAPublicKey { 163 | BigInt modulus; 164 | BigInt publicExponent; 165 | } 166 | 167 | class RSAPrivateKey { 168 | int version; 169 | BigInt modulus; 170 | BigInt publicExponent; 171 | BigInt privateExponent; 172 | BigInt prime1; 173 | BigInt prime2; 174 | BigInt exponent1; 175 | BigInt exponent2; 176 | BigInt coefficient; 177 | } 178 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'package:flutter/material.dart'; 7 | 8 | import './crypto/crypto_provider.dart' as crypto; 9 | 10 | // 公钥 11 | final publicKey = 12 | """"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmPW2SwJFldGVB1SM82VYvSZYR 13 | F1H5DREUiDK2SLnksxHAV/roC1uB44a4siUehJ9AKeV/g58pVrjhX3eSiBh9Khom 14 | /S2hEWF2n/6+lqqiwQi1W5rjl86v+dI2F6NgbPFpfesrRjWD9uskT2VX/ZJuMRLz 15 | 8VPIyQOM9TW3PkMYBQIDAQAB"""; 16 | 17 | // 私钥 (pkcs8) 18 | final privateKey = 19 | """MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKY9bZLAkWV0ZUHV 20 | IzzZVi9JlhEXUfkNERSIMrZIueSzEcBX+ugLW4HjhriyJR6En0Ap5X+DnylWuOFf 21 | d5KIGH0qGib9LaERYXaf/r6WqqLBCLVbmuOXzq/50jYXo2Bs8Wl96ytGNYP26yRP 22 | ZVf9km4xEvPxU8jJA4z1Nbc+QxgFAgMBAAECgYArZVW5PXO3HE9ihBUSyVlqNrdp 23 | 9sB7VyHiTjuOwiVkwiocH9trv6s/mPmONVLjSJOZ2FYEl4Nw8yaIDrfUFJrvhdbh 24 | HJnwkO27Wo5jEfm2qGCwgQNtUACoIH637LXfP81v5I7eZtEa7kfO8Axpp3czvO1H 25 | dIAlOI8rU4jb3fB1cQJBANLgfHd/CDro1gtvTrUeTw/lqsKVScGiHn+pmT+THed6 26 | ftJ2MAJVcL/0H8+fFN5mRypCL7LQyPO48dTmfY9PbocCQQDJz8xZGq2BNAd3gSrN 27 | i3q++SEyjRPzDfr8AGJBJF8qtslcSYrVB/jjPx/qNNlMxOoXnpozBojzVTO3UirM 28 | J/wTAkEAzb930YOhPREGHnwImFCtJT6ZYGcWYpXSGg8Y1d2tlLeA28myx+QjMTZ4 29 | fzOgwemaz9FqBpcNKjctxOLqaRRAKwJAXPZwznbgh8zcx6rjea2PjFscdLnR/7tn 30 | 6x+OIy3K/NUYan+iCUHT33JblDpmAtwObXTs2SZgfZ645PBfsI2WqwJAGJxnG8+w 31 | iCnzN0CIZvG96tfOZmz0lkM4NSHDwdCSbagJlZccOtodpn00Dzy+l0t+oFe0Xm3R 32 | A0WkPzQX/seO0Q=="""; 33 | 34 | void main() => runApp(new MyApp()); 35 | 36 | void Test() { 37 | 38 | // final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........,当链接进行查询时,如果没有定义id,就有可能出现不同类别的内容,但是名字相同,例如某专辑的名字和某个app的名字重合。这时mt就起作用了'; 39 | // final plainText = '{"status:": 1}'; 40 | // final plainText = '{"status:": 1}, 本文基本上是将dart官网部分内容进行翻译。'; 41 | final plainText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit ........。本文基本上是将dart官网部分内容进行翻译,没兴趣的请出门左转至Dart的官网,有兴趣的同志请继续阅读本文。Flutter教程在这里通常,映射是一个有键和值的对象。 键和值都可以是任何类型的对象。 每个键只出现一次,但您可以多次使用相同的值。Dart的Map支持由映射文字和Map。int和double都是num的子类型。 num类型包括基本运算符,如+, - ,/和*,也是你可以找到abs(),ceil()和floor()以及其他方法的地方。 (按位运算符,如>>,在int类中有定义。)如果num及其子类没有您要想要内容,那dart:math库可能有您想要的。Dart字符串是一系列UTF-16代码单元。 您可以使用单引号或双引号来创建字符串:您可以使用{expression}将表达式的值放在字符串中。如果表达式是标识符,则可以跳过{}。 要获取对应于对象的字符串,Dart调用对象的toString()方法。为了表示布尔值,Dart有一个名为bool的类型。 只有两个对象具有bool类型:true和false,它们都是编译时常量。Dart的类型安全意味着您不能使用if(nonbooleanValue)或assert(nonbooleanValue)等代码。 相反,明确检查值,如下所示:也许几乎每种编程语言中最常见的集合是数组或有序的对象组。 在Dart中,数组是List对象,因此大多数人只是将它们称为列表。Dart列表文字看起来像JavaScript数组文字。 这是一个简单的Dart List:"; 42 | print("plainText: " + plainText); 43 | 44 | try { 45 | 46 | // Base64 - Encode 47 | final base64Encoded = crypto.DYFCryptoProvider.yf_base64Encode(plainText); 48 | print("[Base64] Encode: " + base64Encoded); 49 | 50 | // Base64 - Decode 51 | final base64Decoded = crypto.DYFCryptoProvider.yf_base64Decode(base64Encoded); 52 | print("[Base64] Decode: " + base64Decoded); 53 | 54 | // MD5 - 32 Bits Encode 55 | final md5Hash = crypto.DYFCryptoProvider.md5Encode(plainText); 56 | print("[MD5] Hash: " + md5Hash); 57 | 58 | // MD5 - 16 Bits Encode 59 | final md5b16hash = crypto.DYFCryptoProvider.bit16md5Enconde(plainText); 60 | print("[MD5] 16 Bits Hash: " + md5b16hash); 61 | 62 | // AES Key 63 | // final aesKey = "smMQI8dMK2nOMUR0TdpBYQUnLpbW8kjHrdy86WtU6eB1Ff6mYveYzezopmbjwBZEjPQmg"; 64 | final aesKey = "smMQI8dMK2"; 65 | print("[AES] Key: " + aesKey); 66 | 67 | // AES - Encrypt 68 | String aesEncryptedText = crypto.DYFCryptoProvider.aesEncrypt(plainText, aesKey); 69 | print("[AES] Encrypted Text: " + aesEncryptedText); 70 | 71 | // AES - Decrypt 72 | String aesDecryptedText = crypto.DYFCryptoProvider.aesDecrypt(aesEncryptedText, aesKey); 73 | print("[AES] Decrypted Text: " + aesDecryptedText); 74 | 75 | // RSA - Encrypt 76 | String rsaEncryptedText = crypto.DYFCryptoProvider.rsaEncrypt(plainText, publicKey); 77 | print("[RSA] Encrypted Text: " + rsaEncryptedText); 78 | 79 | // RSA - Decrypt 80 | String rsaDecryptedText = crypto.DYFCryptoProvider.rsaDecrypt(rsaEncryptedText, privateKey); 81 | print("[RSA] Decrypted Text: " + rsaDecryptedText); 82 | 83 | // RSA - Sign 84 | String signature = crypto.DYFCryptoProvider.rsaSign(plainText, privateKey); 85 | print("[RSA] Signature: " + signature); 86 | 87 | // RSA - Verify 88 | bool ret = crypto.DYFCryptoProvider.rsaVerify(signature, plainText, publicKey); 89 | print("[RSA] Signature Verification: " + ret.toString()); 90 | 91 | } catch (e) { 92 | 93 | print("e: $e"); 94 | } 95 | 96 | } 97 | 98 | class MyApp extends StatelessWidget { 99 | // This widget is the root of your application. 100 | @override 101 | Widget build(BuildContext context) { 102 | 103 | Test(); 104 | 105 | return new MaterialApp( 106 | title: 'Flutter Demo', 107 | theme: new ThemeData( 108 | // This is the theme of your application. 109 | // 110 | // Try running your application with "flutter run". You'll see the 111 | // application has a blue toolbar. Then, without quitting the app, try 112 | // changing the primarySwatch below to Colors.green and then invoke 113 | // "hot reload" (press "r" in the console where you ran "flutter run", 114 | // or press Run > Flutter Hot Reload in IntelliJ). Notice that the 115 | // counter didn't reset back to zero; the application is not restarted. 116 | primarySwatch: Colors.blue, 117 | ), 118 | home: new MyHomePage(title: 'Flutter Demo Home Page'), 119 | ); 120 | } 121 | } 122 | 123 | class MyHomePage extends StatefulWidget { 124 | MyHomePage({Key key, this.title}) : super(key: key); 125 | 126 | // This widget is the home page of your application. It is stateful, meaning 127 | // that it has a State object (defined below) that contains fields that affect 128 | // how it looks. 129 | 130 | // This class is the configuration for the state. It holds the values (in this 131 | // case the title) provided by the parent (in this case the App widget) and 132 | // used by the build method of the State. Fields in a Widget subclass are 133 | // always marked "final". 134 | 135 | final String title; 136 | 137 | @override 138 | _MyHomePageState createState() => new _MyHomePageState(); 139 | } 140 | 141 | class _MyHomePageState extends State { 142 | int _counter = 0; 143 | 144 | void _incrementCounter() { 145 | setState(() { 146 | // This call to setState tells the Flutter framework that something has 147 | // changed in this State, which causes it to rerun the build method below 148 | // so that the display can reflect the updated values. If we changed 149 | // _counter without calling setState(), then the build method would not be 150 | // called again, and so nothing would appear to happen. 151 | _counter++; 152 | }); 153 | } 154 | 155 | @override 156 | Widget build(BuildContext context) { 157 | // This method is rerun every time setState is called, for instance as done 158 | // by the _incrementCounter method above. 159 | // 160 | // The Flutter framework has been optimized to make rerunning build methods 161 | // fast, so that you can just rebuild anything that needs updating rather 162 | // than having to individually change instances of widgets. 163 | return new Scaffold( 164 | appBar: new AppBar( 165 | // Here we take the value from the MyHomePage object that was created by 166 | // the App.build method, and use it to set our appbar title. 167 | title: new Text(widget.title), 168 | ), 169 | body: new Center( 170 | // Center is a layout widget. It takes a single child and positions it 171 | // in the middle of the parent. 172 | child: new Column( 173 | // Column is also layout widget. It takes a list of children and 174 | // arranges them vertically. By default, it sizes itself to fit its 175 | // children horizontally, and tries to be as tall as its parent. 176 | // 177 | // Invoke "debug paint" (press "p" in the console where you ran 178 | // "flutter run", or select "Toggle Debug Paint" from the Flutter tool 179 | // window in IntelliJ) to see the wireframe for each widget. 180 | // 181 | // Column has various properties to control how it sizes itself and 182 | // how it positions its children. Here we use mainAxisAlignment to 183 | // center the children vertically; the main axis here is the vertical 184 | // axis because Columns are vertical (the cross axis would be 185 | // horizontal). 186 | mainAxisAlignment: MainAxisAlignment.center, 187 | children: [ 188 | new Text( 189 | 'You have pushed the button this many times:', 190 | ), 191 | new Text( 192 | '$_counter', 193 | style: Theme.of(context).textTheme.display1, 194 | ), 195 | ], 196 | ), 197 | ), 198 | floatingActionButton: new FloatingActionButton( 199 | onPressed: _incrementCounter, 200 | tooltip: 'Increment', 201 | child: new Icon(Icons.add), 202 | ), // This trailing comma makes auto-formatting nicer for build methods. 203 | ); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /lib/string_utils.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dyf on 2018/8/31. 3 | // Copyright (c) 2018 dyf. 4 | // 5 | 6 | import 'dart:convert'; 7 | import 'dart:math' show Random; 8 | import './crypto/crypto_provider.dart' as crypto; 9 | 10 | // Updated and unreal keys. 11 | class KeyConstants { 12 | 13 | static final kComm = "##@...#FiQKBgQCmPW2SwJFl}"; 14 | 15 | static final kPublic = 16 | "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmPW2SwJFldGVB1SM82VYvSZYR...8VPIyQOM9TW3PkMYBQIDAQAB"; 17 | 18 | static final kPrivate = 19 | "MIICXAIBAAKBgQCmPW2SwJFldGVB1SM82VYvSZYRF1H5DREUiDK2SLnksxHAV/ro...CZWXHDraHaZ9NA88vpdLfqBXtF5t0QNFpD80F/7HjtE="; 20 | } 21 | 22 | class RandomObjectGenerator { 23 | 24 | int genRandomNumber() { 25 | var max = 1 << 32; 26 | return Random().nextInt(max); 27 | } 28 | 29 | String genRandomString({int length: 20}) { 30 | var buffer = StringBuffer(); 31 | 32 | for (var i = 0; i < length; i++) { 33 | int r = new Random().nextInt(2); 34 | 35 | var s = (r == 1 ? "A" : "a"); 36 | int start = s.codeUnitAt(0); 37 | int c = start + Random().nextInt(26); 38 | 39 | buffer.writeCharCode(c); 40 | } 41 | 42 | return buffer.toString(); 43 | } 44 | 45 | } 46 | 47 | abstract class BaseStringUtils { 48 | String urlEncode(String s); 49 | String urlDecode(String s); 50 | String apiEncode(String s); 51 | String apiDecode(String s); 52 | } 53 | 54 | class StringUtils extends RandomObjectGenerator implements BaseStringUtils { 55 | 56 | @override 57 | String genRandomString({int length: 20}) => super.genRandomString(length: length); 58 | 59 | String urlEncode(String s) { 60 | return Uri.encodeQueryComponent(s); 61 | } 62 | 63 | String urlDecode(String s) { 64 | return Uri.decodeQueryComponent(s); 65 | } 66 | 67 | String apiEncode(String s) { 68 | if (s == null) throw ArgumentError("The input is null"); 69 | if (s.isEmpty) return s; 70 | 71 | try { 72 | String randomKey = genRandomString(); 73 | print("randomKey: $randomKey"); 74 | String middleKey = randomKey + KeyConstants.kComm; 75 | print("middleKey: $middleKey"); 76 | 77 | String realKey = crypto.DYFCryptoProvider.bit16md5Enconde(middleKey); 78 | String mParam = crypto.DYFCryptoProvider.aesEncrypt(s, realKey); 79 | 80 | var middleMap = Map(); 81 | middleMap["p"] = mParam; 82 | middleMap["k"] = randomKey; 83 | var jp = json.encode(middleMap); 84 | print("jp: $jp"); 85 | 86 | String ciphertext = crypto.DYFCryptoProvider.rsaEncrypt(jp, KeyConstants.kPublic); 87 | print("ciphertext: $ciphertext"); 88 | 89 | return ciphertext; 90 | } catch (e) { 91 | print("e: $e"); 92 | } 93 | 94 | return null; 95 | } 96 | 97 | String apiDecode(String s) { 98 | if (s == null) throw ArgumentError("The input is null"); 99 | if (s.isEmpty) return s; 100 | 101 | try { 102 | String data = crypto.DYFCryptoProvider.rsaDecrypt(s, KeyConstants.kPrivate); 103 | 104 | var map = json.decode(data); 105 | var mParam = map["p"]; 106 | var randomKey = map["k"]; 107 | print("randomKey: $randomKey"); 108 | 109 | String middleKey = randomKey + KeyConstants.kComm; 110 | print("middleKey: $middleKey"); 111 | 112 | String realKey = crypto.DYFCryptoProvider.bit16md5Enconde(middleKey); 113 | String decodedText = crypto.DYFCryptoProvider.aesDecrypt(mParam, realKey); 114 | 115 | return decodedText; 116 | } catch (e) { 117 | print("e: $e"); 118 | } 119 | 120 | return null; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dart_crypto 2 | description: A new Flutter project. 3 | 4 | dependencies: 5 | flutter: 6 | sdk: flutter 7 | 8 | # The following adds the Cupertino Icons font to your application. 9 | # Use with the CupertinoIcons class for iOS style icons. 10 | cupertino_icons: ^0.1.2 11 | # gbk2utf8: ^0.0.1 12 | # ninja: ^1.0.0 13 | 14 | # ================================ 15 | # Crypto requires these pakages. 16 | # ================================ 17 | crypto: ^2.0.5 18 | asn1lib: ^0.5.1 19 | pointycastle: ^1.0.0-rc2 20 | # ================================ 21 | 22 | http: ^0.11.3+16 23 | 24 | dependency_overrides: 25 | reflectable: 2.0.2 26 | analyzer: 0.32.4 27 | path: 1.6.2 28 | 29 | dev_dependencies: 30 | flutter_test: 31 | sdk: flutter 32 | 33 | # For information on the generic Dart part of this file, see the 34 | # following page: https://www.dartlang.org/tools/pub/pubspec 35 | 36 | # The following section is specific to Flutter. 37 | flutter: 38 | 39 | # The following line ensures that the Material Icons font is 40 | # included with your application, so that you can use the icons in 41 | # the material Icons class. 42 | uses-material-design: true 43 | 44 | # To add assets to your application, add an assets section, like this: 45 | # assets: 46 | # - images/a_dot_burr.jpeg 47 | # - images/a_dot_ham.jpeg 48 | 49 | # An image asset can refer to one or more resolution-specific "variants", see 50 | # https://flutter.io/assets-and-images/#resolution-aware. 51 | 52 | # For details regarding adding assets from package dependencies, see 53 | # https://flutter.io/assets-and-images/#from-packages 54 | 55 | # To add custom fonts to your application, add a fonts section here, 56 | # in this "flutter" section. Each entry in this list should have a 57 | # "family" key with the font family name, and a "fonts" key with a 58 | # list giving the asset and other descriptors for the font. For 59 | # example: 60 | # fonts: 61 | # - family: Schyler 62 | # fonts: 63 | # - asset: fonts/Schyler-Regular.ttf 64 | # - asset: fonts/Schyler-Italic.ttf 65 | # style: italic 66 | # - family: Trajan Pro 67 | # fonts: 68 | # - asset: fonts/TrajanPro.ttf 69 | # - asset: fonts/TrajanPro_Bold.ttf 70 | # weight: 700 71 | # 72 | # For details regarding fonts from package dependencies, 73 | # see https://flutter.io/custom-fonts/#from-packages 74 | -------------------------------------------------------------------------------- /test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter 3 | // provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to 4 | // find child widgets in the widget tree, read text, and verify that the values of widget properties 5 | // are correct. 6 | 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter_test/flutter_test.dart'; 9 | 10 | import 'package:dart_crypto/main.dart'; 11 | 12 | void main() { 13 | testWidgets('Counter increments smoke test', (WidgetTester tester) async { 14 | // Build our app and trigger a frame. 15 | await tester.pumpWidget(new MyApp()); 16 | 17 | // Verify that our counter starts at 0. 18 | expect(find.text('0'), findsOneWidget); 19 | expect(find.text('1'), findsNothing); 20 | 21 | // Tap the '+' icon and trigger a frame. 22 | await tester.tap(find.byIcon(Icons.add)); 23 | await tester.pump(); 24 | 25 | // Verify that our counter has incremented. 26 | expect(find.text('0'), findsNothing); 27 | expect(find.text('1'), findsOneWidget); 28 | }); 29 | } 30 | --------------------------------------------------------------------------------