NEW: added ccc_fplugin
This commit is contained in:
parent
b8e78f13af
commit
c470345f45
|
@ -0,0 +1,6 @@
|
||||||
|
.dart_tool/
|
||||||
|
.packages
|
||||||
|
.pub/
|
||||||
|
build/
|
||||||
|
.idea/vcs.xml
|
||||||
|
.DS_Store
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||||
|
</project>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Dart SDK">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/async" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/collection" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/convert" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/core" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/developer" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/html" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/io" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/isolate" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/math" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/mirrors" />
|
||||||
|
<root url="file:///Users/j3g/apps/flutter/bin/cache/dart-sdk/lib/typed_data" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Flutter Plugins" type="FlutterPluginsLibraryType">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="file://$PROJECT_DIR$" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Flutter for Android">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar:///Users/j3g/apps/flutter/bin/cache/artifacts/engine/android-arm/flutter.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="io.flutter" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/ccc_fplugin.iml" filepath="$PROJECT_DIR$/ccc_fplugin.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/android/ccc_fplugin_android.iml" filepath="$PROJECT_DIR$/android/ccc_fplugin_android.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/example/android/ccc_fplugin_example_android.iml" filepath="$PROJECT_DIR$/example/android/ccc_fplugin_example_android.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="example/lib/main.dart" type="FlutterRunConfigurationType" factoryName="Flutter" singleton="false">
|
||||||
|
<option name="filePath" value="$PROJECT_DIR$/example/lib/main.dart" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,217 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AndroidLogFilters">
|
||||||
|
<option name="TOOL_WINDOW_CONFIGURED_FILTER" value="Show only selected application" />
|
||||||
|
</component>
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="90767928-27ac-4d7f-8e72-d19bf99d8c4d" name="Default Changelist" comment="" />
|
||||||
|
<ignored path="$PROJECT_DIR$/.dart_tool/" />
|
||||||
|
<ignored path="$PROJECT_DIR$/.idea/" />
|
||||||
|
<ignored path="$PROJECT_DIR$/.pub/" />
|
||||||
|
<ignored path="$PROJECT_DIR$/build/" />
|
||||||
|
<ignored path="$PROJECT_DIR$/example/.pub/" />
|
||||||
|
<ignored path="$PROJECT_DIR$/example/build/" />
|
||||||
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="FileEditorManager">
|
||||||
|
<splitter split-orientation="horizontal" split-proportion="0.5">
|
||||||
|
<split-first>
|
||||||
|
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||||
|
<file pinned="false" current-in-tab="true">
|
||||||
|
<entry file="file://$PROJECT_DIR$/lib/ccc_fplugin.dart">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="465">
|
||||||
|
<caret line="31" selection-start-line="31" selection-end-line="31" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#0#20#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
</leaf>
|
||||||
|
</split-first>
|
||||||
|
<split-second>
|
||||||
|
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="255">
|
||||||
|
<caret line="17" column="8" selection-start-line="17" selection-start-column="8" selection-end-line="17" selection-end-column="8" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="true">
|
||||||
|
<entry file="file://$PROJECT_DIR$/lib/crypto_mixin.dart">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state>
|
||||||
|
<folding>
|
||||||
|
<element signature="e#0#22#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
</leaf>
|
||||||
|
</split-second>
|
||||||
|
</splitter>
|
||||||
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="IdeDocumentHistory">
|
||||||
|
<option name="CHANGED_PATHS">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pubspec.yaml" />
|
||||||
|
<option value="$PROJECT_DIR$/example/lib/main.dart" />
|
||||||
|
<option value="$PROJECT_DIR$/lib/ccc_fplugin.dart" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectFrameBounds">
|
||||||
|
<option name="x" value="607" />
|
||||||
|
<option name="y" value="23" />
|
||||||
|
<option name="width" value="1953" />
|
||||||
|
<option name="height" value="1417" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
|
<component name="ProjectView">
|
||||||
|
<navigator currentView="ProjectPane" proportions="" version="1">
|
||||||
|
<foldersAlwaysOnTop value="true" />
|
||||||
|
</navigator>
|
||||||
|
<panes>
|
||||||
|
<pane id="PackagesPane" />
|
||||||
|
<pane id="Scope" />
|
||||||
|
<pane id="ProjectPane">
|
||||||
|
<subPane>
|
||||||
|
<expand>
|
||||||
|
<path>
|
||||||
|
<item name="ccc_fplugin" type="b2602c69:ProjectViewProjectNode" />
|
||||||
|
<item name="ccc_fplugin" type="462c0819:PsiDirectoryNode" />
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<item name="ccc_fplugin" type="b2602c69:ProjectViewProjectNode" />
|
||||||
|
<item name="ccc_fplugin" type="462c0819:PsiDirectoryNode" />
|
||||||
|
<item name="lib" type="462c0819:PsiDirectoryNode" />
|
||||||
|
</path>
|
||||||
|
</expand>
|
||||||
|
<select />
|
||||||
|
</subPane>
|
||||||
|
</pane>
|
||||||
|
<pane id="AndroidView" />
|
||||||
|
</panes>
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent">
|
||||||
|
<property name="dart.analysis.tool.window.force.activate" value="false" />
|
||||||
|
<property name="io.flutter.reload.alreadyRun" value="true" />
|
||||||
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
|
<property name="show.migrate.to.gradle.popup" value="false" />
|
||||||
|
</component>
|
||||||
|
<component name="RunDashboard">
|
||||||
|
<option name="ruleStates">
|
||||||
|
<list>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="StatusDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="SvnConfiguration">
|
||||||
|
<configuration />
|
||||||
|
</component>
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="90767928-27ac-4d7f-8e72-d19bf99d8c4d" name="Default Changelist" comment="" />
|
||||||
|
<created>1557699660369</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1557699660369</updated>
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="TodoView">
|
||||||
|
<todo-panel id="selected-file">
|
||||||
|
<is-autoscroll-to-source value="true" />
|
||||||
|
</todo-panel>
|
||||||
|
<todo-panel id="all">
|
||||||
|
<are-packages-shown value="true" />
|
||||||
|
<is-autoscroll-to-source value="true" />
|
||||||
|
</todo-panel>
|
||||||
|
</component>
|
||||||
|
<component name="ToolWindowManager">
|
||||||
|
<frame x="607" y="23" width="1953" height="1417" extended-state="0" />
|
||||||
|
<editor active="true" />
|
||||||
|
<layout>
|
||||||
|
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.14599685" />
|
||||||
|
<window_info id="Captures" order="1" side_tool="true" />
|
||||||
|
<window_info id="Structure" order="2" side_tool="true" />
|
||||||
|
<window_info id="Image Layers" order="3" />
|
||||||
|
<window_info id="Designer" order="4" />
|
||||||
|
<window_info id="Build Variants" order="5" side_tool="true" />
|
||||||
|
<window_info id="Resources Explorer" order="6" />
|
||||||
|
<window_info id="Capture Tool" order="7" />
|
||||||
|
<window_info id="Favorites" order="8" side_tool="true" />
|
||||||
|
<window_info anchor="bottom" auto_hide="true" id="Dart Analysis" order="0" weight="0.32981133" />
|
||||||
|
<window_info anchor="bottom" id="Run" order="1" weight="0.32981133" />
|
||||||
|
<window_info anchor="bottom" id="TODO" order="2" weight="0.32981133" />
|
||||||
|
<window_info anchor="bottom" id="Android Profiler" order="3" show_stripe_button="false" />
|
||||||
|
<window_info anchor="bottom" id="Logcat" order="4" weight="0.32981133" />
|
||||||
|
<window_info anchor="bottom" id="Debug" order="5" />
|
||||||
|
<window_info anchor="bottom" id="Terminal" order="6" />
|
||||||
|
<window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
|
||||||
|
<window_info anchor="bottom" id="Flutter Performance" order="8" side_tool="true" />
|
||||||
|
<window_info anchor="bottom" id="Version Control" order="9" />
|
||||||
|
<window_info anchor="bottom" id="Find" order="10" />
|
||||||
|
<window_info anchor="bottom" auto_hide="true" id="Messages" order="11" weight="0.32981133" />
|
||||||
|
<window_info anchor="right" id="Device File Explorer" order="0" side_tool="true" />
|
||||||
|
<window_info anchor="right" id="Capture Analysis" order="1" />
|
||||||
|
<window_info anchor="right" id="Theme Preview" order="2" />
|
||||||
|
<window_info anchor="right" id="Flutter Inspector" order="3" />
|
||||||
|
<window_info anchor="right" id="Flutter Outline" order="4" weight="0.3294979" />
|
||||||
|
<window_info anchor="right" id="Palette	" order="5" />
|
||||||
|
</layout>
|
||||||
|
</component>
|
||||||
|
<component name="editorHistoryManager">
|
||||||
|
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="450">
|
||||||
|
<caret line="34" column="13" lean-forward="true" selection-start-line="34" selection-start-column="13" selection-end-line="34" selection-end-column="13" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="255">
|
||||||
|
<caret line="17" column="8" selection-start-line="17" selection-start-column="8" selection-end-line="17" selection-end-column="8" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/lib/crypto_mixin.dart">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state>
|
||||||
|
<folding>
|
||||||
|
<element signature="e#0#22#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/lib/ccc_fplugin.dart">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="465">
|
||||||
|
<caret line="31" selection-start-line="31" selection-end-line="31" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#0#20#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,10 @@
|
||||||
|
# This file tracks properties of this Flutter project.
|
||||||
|
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||||
|
#
|
||||||
|
# This file should be version controlled and should not be manually edited.
|
||||||
|
|
||||||
|
version:
|
||||||
|
revision: 8661d8aecd626f7f57ccbcb735553edc05a2e713
|
||||||
|
channel: stable
|
||||||
|
|
||||||
|
project_type: plugin
|
|
@ -0,0 +1,3 @@
|
||||||
|
Version
|
||||||
|
-------
|
||||||
|
* 0.0.1
|
|
@ -0,0 +1 @@
|
||||||
|
TODO: Add your license here.
|
|
@ -0,0 +1,4 @@
|
||||||
|
==================================
|
||||||
|
Copius Cipher Chain Flutter Plugin
|
||||||
|
==================================
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
*.iml
|
||||||
|
.gradle
|
||||||
|
/local.properties
|
||||||
|
/.idea/workspace.xml
|
||||||
|
/.idea/libraries
|
||||||
|
.DS_Store
|
||||||
|
/build
|
||||||
|
/captures
|
|
@ -0,0 +1,43 @@
|
||||||
|
group 'io.malloc.ccc.ccc_fplugin'
|
||||||
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.android.library'
|
||||||
|
android {
|
||||||
|
compileSdkVersion 28
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 23
|
||||||
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
}
|
||||||
|
lintOptions {
|
||||||
|
disable 'InvalidPackage'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// implementation 'io.malloc.ccc:nc-jni:1.1@aar'
|
||||||
|
// yay, we can pull wolfssl-jni.aar into our project!!
|
||||||
|
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
||||||
|
// doesn't work because google flutter team cascaded embedded spaghetti gradle dependencies
|
||||||
|
// implementation project(":nc-lib")
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
org.gradle.jvmargs=-Xmx1536M
|
||||||
|
android.useAndroidX=true
|
||||||
|
android.enableJetifier=true
|
Binary file not shown.
|
@ -0,0 +1,2 @@
|
||||||
|
rootProject.name = 'ccc_fplugin'
|
||||||
|
// include ':nc-lib'
|
|
@ -0,0 +1,3 @@
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="io.malloc.ccc.ccc_fplugin">
|
||||||
|
</manifest>
|
|
@ -0,0 +1,108 @@
|
||||||
|
package io.malloc.ccc.cc;
|
||||||
|
|
||||||
|
import com.wolfssl.wolfcrypt.Aes;
|
||||||
|
import io.malloc.ccc.nc.Util;
|
||||||
|
|
||||||
|
|
||||||
|
public class AesCipher implements ICipher {
|
||||||
|
|
||||||
|
final int PADDING_SIZE = 16;
|
||||||
|
|
||||||
|
private Aes aes;
|
||||||
|
private byte[] iv;
|
||||||
|
private byte[] key;
|
||||||
|
private boolean isEnc;
|
||||||
|
|
||||||
|
|
||||||
|
public AesCipher(byte[] key, byte[] iv, boolean isEnc) throws NastySizeException {
|
||||||
|
init(key, iv, isEnc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(byte[] key, byte[] iv, boolean isEnc) throws NastySizeException {
|
||||||
|
checkSizes(key.length, iv.length);
|
||||||
|
this.iv = iv;
|
||||||
|
this.key = key;
|
||||||
|
this.isEnc = isEnc;
|
||||||
|
if(isEnc) {
|
||||||
|
System.out.println("Aes.ENCRYPT_MODE");
|
||||||
|
aes = new Aes(key, iv, Aes.ENCRYPT_MODE);
|
||||||
|
// aes.setKey(iv, key, Aes.ENCRYPT_MODE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Aes.DECRYPT_MODE");
|
||||||
|
aes = new Aes(key, iv, Aes.DECRYPT_MODE);
|
||||||
|
// aes.setKey(iv, key, Aes.DECRYPT_MODE);
|
||||||
|
}
|
||||||
|
System.out.println("iv=="+Util.b2h(iv));
|
||||||
|
System.out.println("key=="+Util.b2h(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] enc(byte[] data) throws NotPayingAttentionException {
|
||||||
|
byte[] result;
|
||||||
|
System.out.println("data=="+Util.b2h(data));
|
||||||
|
if(isEnc) {
|
||||||
|
byte[] newData = padData(data);
|
||||||
|
System.out.println("newData=="+Util.b2h(newData));
|
||||||
|
result = aes.update(newData, 0, newData.length);
|
||||||
|
System.out.println("result=="+Util.b2h(result));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new NotPayingAttentionException("you are encrypting while in decrypting mode");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] dec(byte[] data) throws NotPayingAttentionException {
|
||||||
|
byte[] result;
|
||||||
|
if(data.length % 16 != 0)
|
||||||
|
throw new NotPayingAttentionException("data is not multiple of 16 bytes");
|
||||||
|
if(!isEnc) {
|
||||||
|
result = aes.update(data, 0, data.length);
|
||||||
|
System.out.println("dec() result=="+Util.b2h(result)+"; length=="+result.length);
|
||||||
|
result = unPadData(result);
|
||||||
|
System.out.println("dec() result=="+Util.b2h(result)+"; length=="+result.length);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new NotPayingAttentionException("you are decrypting while in encrypting mode");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
aes.releaseNativeStruct();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkSizes(int keyLen, int ivLen) throws NastySizeException {
|
||||||
|
if (keyLen != 16 && keyLen != 24 && keyLen != 32)
|
||||||
|
throw new NastySizeException("Key isn't 16, 24, 32 bytes; length is "+keyLen+" bytes");
|
||||||
|
if (ivLen != 16 && ivLen != 24 && ivLen != 32)
|
||||||
|
throw new NastySizeException("IV isn't 16 bytes; IV is "+ivLen+" bytes");
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] padData(byte[] data) {
|
||||||
|
int remainder = data.length % PADDING_SIZE;
|
||||||
|
System.out.println("[J3G] data.length % 16 == "+remainder);
|
||||||
|
if(remainder != 0) {
|
||||||
|
remainder = PADDING_SIZE - remainder;
|
||||||
|
byte[] newData = new byte[data.length+remainder+PADDING_SIZE];
|
||||||
|
System.arraycopy(data, 0, newData, 0, data.length);
|
||||||
|
for(int i=data.length; i<newData.length; i++)
|
||||||
|
newData[i] = (byte)remainder;
|
||||||
|
|
||||||
|
return newData;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] unPadData(byte[] data) {
|
||||||
|
byte b = data[data.length-1];
|
||||||
|
System.out.println("padding=="+b);
|
||||||
|
byte[] newData = new byte[data.length-(b+PADDING_SIZE)];
|
||||||
|
System.arraycopy(data, 0, newData, 0, newData.length);
|
||||||
|
return newData;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package io.malloc.ccc.cc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
- this allows the library to encrypt with a deterministic pattern such that
|
||||||
|
any desperate combo will work inter-changeably
|
||||||
|
- Ccc_enc( CipherCombo combo, Password pass, Message msg )
|
||||||
|
*/
|
||||||
|
public class CipherCombo {
|
||||||
|
// Ccc_enc( CipherCombo combo, Password pass, Message msg )
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package io.malloc.ccc.cc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
- this allows a specific pattern of ciphers to be set
|
||||||
|
- Ccc_enc( CipherPattern pattern, Password pass, Message msg )
|
||||||
|
*/
|
||||||
|
public class CipherPattern {
|
||||||
|
// Ccc_enc( CipherPattern pattern, Password pass, Message msg )
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package io.malloc.ccc.cc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
- this allows anyone to use the library and expect the library to know the best,
|
||||||
|
more powerful cipher; fastest cipher that is secure; most secure cipher
|
||||||
|
- Ccc_enc ( EasyCipher cipher, Password pass, Message msg )
|
||||||
|
- EasyCipher: ( BEST, FAST, ... )
|
||||||
|
*/
|
||||||
|
public class EasyCipher {
|
||||||
|
// EasyCipher: ( BEST, FAST, ... )
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package io.malloc.ccc.cc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
- this allows the library to encrypt with a single cipher
|
||||||
|
- Ccc_enc( Cipher cipher, Password pass, Message msg )
|
||||||
|
*/
|
||||||
|
public interface ICipher {
|
||||||
|
|
||||||
|
void init(byte[] key, byte[] iv, boolean isEnc) throws Exception;
|
||||||
|
|
||||||
|
byte[] enc(byte[] data) throws Exception;
|
||||||
|
|
||||||
|
byte[] dec(byte[] data) throws Exception;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package io.malloc.ccc.cc;
|
||||||
|
|
||||||
|
|
||||||
|
public class NastySizeException extends Exception {
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
NastySizeException(String str) {
|
||||||
|
msg = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ("[CCC:NastySizeException] "+msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package io.malloc.ccc.cc;
|
||||||
|
|
||||||
|
public class NotPayingAttentionException extends Exception {
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
NotPayingAttentionException(String str) {
|
||||||
|
msg = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ("[CCC:NotPayingAttentionException] "+msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
package io.malloc.ccc.ccc_fplugin;
|
||||||
|
|
||||||
|
import com.wolfssl.wolfcrypt.Aes;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import io.flutter.plugin.common.MethodCall;
|
||||||
|
import io.flutter.plugin.common.MethodChannel;
|
||||||
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||||
|
import io.flutter.plugin.common.MethodChannel.Result;
|
||||||
|
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
||||||
|
import io.malloc.ccc.nc.AesTest;
|
||||||
|
import io.malloc.ccc.cc.AesCipher;
|
||||||
|
import io.malloc.ccc.nc.Util;
|
||||||
|
|
||||||
|
/** CccFpluginPlugin */
|
||||||
|
public class CccFpluginPlugin implements MethodCallHandler {
|
||||||
|
/**
|
||||||
|
* Plugin registration.
|
||||||
|
*/
|
||||||
|
public static void registerWith(Registrar registrar) {
|
||||||
|
final MethodChannel channel = new MethodChannel(registrar.messenger(), "ccc_fplugin");
|
||||||
|
channel.setMethodCallHandler(new CccFpluginPlugin());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMethodCall(MethodCall call, Result result) {
|
||||||
|
byte[] iv;
|
||||||
|
byte[] key;
|
||||||
|
byte[] pData;
|
||||||
|
byte[] eData;
|
||||||
|
AesCipher aes;
|
||||||
|
Aes enc;
|
||||||
|
Aes dec;
|
||||||
|
try {
|
||||||
|
switch (call.method) {
|
||||||
|
case "getPlatformVersion":
|
||||||
|
result.success("Android " + android.os.Build.VERSION.RELEASE);
|
||||||
|
break;
|
||||||
|
//
|
||||||
|
// Tests
|
||||||
|
//
|
||||||
|
case "aesTest":
|
||||||
|
AesTest aesTest = new AesTest();
|
||||||
|
aesTest.testEncDec();
|
||||||
|
result.success("yay");
|
||||||
|
break;
|
||||||
|
//
|
||||||
|
// Encrypt String
|
||||||
|
//
|
||||||
|
case "aesEnc":
|
||||||
|
System.out.println("[J3G] 111");
|
||||||
|
iv = call.argument("iv");
|
||||||
|
key = call.argument("key");
|
||||||
|
pData = ((String)call.argument("pText")).getBytes("UTF-8");
|
||||||
|
System.out.println("[J3G] 222");
|
||||||
|
aes = new AesCipher(key, iv, true);
|
||||||
|
System.out.println("[J3G] 333");
|
||||||
|
eData = aes.enc(pData);
|
||||||
|
System.out.println("[J3G] 444");
|
||||||
|
aes.destroy();
|
||||||
|
result.success(eData);
|
||||||
|
break;
|
||||||
|
//
|
||||||
|
// Encrypt Uint
|
||||||
|
//
|
||||||
|
case "aesEncUint":
|
||||||
|
// pData = call.argument("pData");
|
||||||
|
// String hexStr1 = Util.b2h(pData);
|
||||||
|
// System.out.println(hexStr1);
|
||||||
|
|
||||||
|
System.out.println("[J3G] 111");
|
||||||
|
iv = call.argument("iv");
|
||||||
|
key = call.argument("key");
|
||||||
|
pData = call.argument("pData");
|
||||||
|
System.out.println("[J3G] 222");
|
||||||
|
aes = new AesCipher(key, iv, true);
|
||||||
|
System.out.println("[J3G] 333");
|
||||||
|
eData = aes.enc(pData);
|
||||||
|
aes.destroy();
|
||||||
|
result.success(eData);
|
||||||
|
break;
|
||||||
|
//
|
||||||
|
// Decrypt
|
||||||
|
//
|
||||||
|
case "aesDec":
|
||||||
|
iv = call.argument("iv");
|
||||||
|
key = call.argument("key");
|
||||||
|
byte[] cData = call.argument("cData");
|
||||||
|
aes = new AesCipher(key, iv, false);
|
||||||
|
pData = aes.dec(cData);
|
||||||
|
aes.destroy();
|
||||||
|
result.success(pData);
|
||||||
|
// dec = new Aes(key, iv, Aes.DECRYPT_MODE);
|
||||||
|
// byte[] decText = dec.update(cData, 0, cData.length);
|
||||||
|
// dec.releaseNativeStruct();
|
||||||
|
// result.success(decText);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result.notImplemented();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
System.out.println("[ERR] exception: "+ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
package io.malloc.ccc.nc;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import com.wolfssl.wolfcrypt.Aes;
|
||||||
|
import com.wolfssl.wolfcrypt.WolfCryptException;
|
||||||
|
|
||||||
|
|
||||||
|
public class AesTest {
|
||||||
|
|
||||||
|
private static final byte[] KEY = Util.h2b("00112233445566778899AABBCCDDEEFF");
|
||||||
|
private static final byte[] IV = Util.h2b("000102030405060708090A0B0C0D0E0F");
|
||||||
|
|
||||||
|
|
||||||
|
public void testEncDec() {
|
||||||
|
|
||||||
|
byte[] key = Util.h2b("2b7e151628aed2a6abf7158809cf4f3c");
|
||||||
|
byte[] iv = Util.h2b("000102030405060708090A0B0C0D0E0F");
|
||||||
|
byte[] in = Util.h2b("6bc1bee22e409f96e93d7e117393172a");
|
||||||
|
byte[] expected = Util.h2b("7649abac8119b246cee98e9b12e9197d");
|
||||||
|
|
||||||
|
byte[] cipher = null;
|
||||||
|
byte[] plain = null;
|
||||||
|
|
||||||
|
Aes enc = new Aes(key, iv, Aes.ENCRYPT_MODE);
|
||||||
|
cipher = enc.update(in, 0, in.length);
|
||||||
|
if ( Arrays.equals(expected, cipher) ) {
|
||||||
|
System.out.println("J3G_YAY: encrypt function working!!");
|
||||||
|
System.out.println("J3G_YAY: "+Util.b2h(expected)+"=="+Util.b2h(cipher));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("J3G_ERR: encrypt isn't working properly");
|
||||||
|
System.out.println("J3G_YAY: "+Util.b2h(expected)+"!="+Util.b2h(cipher));
|
||||||
|
}
|
||||||
|
|
||||||
|
Aes dec = new Aes(key, iv, Aes.DECRYPT_MODE);
|
||||||
|
plain = dec.update(cipher, 0, cipher.length);
|
||||||
|
if ( Arrays.equals(in, plain) ) {
|
||||||
|
System.out.println("J3G_YAY: decrypt function working!!");
|
||||||
|
System.out.println("J3G_YAY: "+Util.b2h(in)+"=="+Util.b2h(plain));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("J3G_ERR: decrypt error");
|
||||||
|
System.out.println("J3G_ERR: "+Util.b2h(in)+"!="+Util.b2h(plain));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free objects */
|
||||||
|
enc.releaseNativeStruct();
|
||||||
|
dec.releaseNativeStruct();
|
||||||
|
|
||||||
|
/* try to re-init and re-use them */
|
||||||
|
enc = new Aes(key, iv, Aes.ENCRYPT_MODE);
|
||||||
|
cipher = enc.update(in, 0, in.length);
|
||||||
|
if ( Arrays.equals(expected, cipher) ) {
|
||||||
|
System.out.println("J3G_YAY: encrypt function working!!");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("J3G_ERR: encrypt isn't working properly");
|
||||||
|
}
|
||||||
|
|
||||||
|
dec = new Aes(key, iv, Aes.DECRYPT_MODE);
|
||||||
|
plain = dec.update(cipher, 0, cipher.length);
|
||||||
|
if ( Arrays.equals(in, plain) ) {
|
||||||
|
System.out.println("J3G_YAY: decrypt function working!!");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("J3G_ERR: decrypt isn't working properly");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free again */
|
||||||
|
enc.releaseNativeStruct();
|
||||||
|
dec.releaseNativeStruct();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void checkSetKeyParams() {
|
||||||
|
/* iv is optional, should not raise. */
|
||||||
|
Aes aes = new Aes(KEY, null, Aes.ENCRYPT_MODE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
aes.setKey(null, IV, Aes.ENCRYPT_MODE);
|
||||||
|
} catch (WolfCryptException e) {
|
||||||
|
System.out.println("ERROR: WolfCrypt: J3G: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
aes.setKey(KEY, IV, Aes.ENCRYPT_MODE);
|
||||||
|
aes.releaseNativeStruct();
|
||||||
|
|
||||||
|
try {
|
||||||
|
aes.setKey(KEY, IV, Aes.ENCRYPT_MODE);
|
||||||
|
} catch (WolfCryptException e) {
|
||||||
|
System.out.println("ERROR: WolfCrypt: J3G: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package io.malloc.ccc.nc;
|
||||||
|
|
||||||
|
import com.wolfssl.wolfcrypt.Aes;
|
||||||
|
|
||||||
|
public class CccAes {
|
||||||
|
|
||||||
|
|
||||||
|
// Aes enc = new Aes(key, iv, Aes.ENCRYPT_MODE);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,220 @@
|
||||||
|
/* RsaTest.java
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.malloc.ccc.nc;
|
||||||
|
|
||||||
|
import com.wolfssl.wolfcrypt.Rsa;
|
||||||
|
import com.wolfssl.wolfcrypt.Rng;
|
||||||
|
import com.wolfssl.wolfcrypt.WolfCryptError;
|
||||||
|
import com.wolfssl.wolfcrypt.WolfCryptException;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class RsaTest {
|
||||||
|
private static Rng rng = new Rng();
|
||||||
|
|
||||||
|
|
||||||
|
public void testEncDec() {
|
||||||
|
// try {
|
||||||
|
Rsa key = new Rsa();
|
||||||
|
rng.init();
|
||||||
|
|
||||||
|
// key.makeKey(1024, 65537, rng);
|
||||||
|
|
||||||
|
if (publicKeyDecodeAndEncodeWithByteBuffer()) {
|
||||||
|
System.out.println("J3G_YAY: RSA working");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("J3G_ERR: RSA broken :(");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (publicKeyDecodeAndEncodeWithByteArray()) {
|
||||||
|
System.out.println("J3G_YAY: RSA working");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("J3G_ERR: RSA broken :(");
|
||||||
|
}
|
||||||
|
|
||||||
|
// }
|
||||||
|
// catch (WolfCryptException e) {
|
||||||
|
// if (e.getError() == WolfCryptError.NOT_COMPILED_IN)
|
||||||
|
// System.out.println("Rsa test skipped: " + e.getError());
|
||||||
|
// }
|
||||||
|
// catch(Exception e) {
|
||||||
|
// System.out.println(e.getMessage());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean publicKeyDecodeAndEncodeWithByteBuffer() {
|
||||||
|
boolean retVal = false;
|
||||||
|
Rsa key = new Rsa();
|
||||||
|
|
||||||
|
ByteBuffer n_in = ByteBuffer.allocateDirect(256); // modulus
|
||||||
|
ByteBuffer e_in = ByteBuffer.allocateDirect(256); // exponent
|
||||||
|
ByteBuffer n_out = ByteBuffer.allocateDirect(256); // modulus
|
||||||
|
ByteBuffer e_out = ByteBuffer.allocateDirect(256); // exponent
|
||||||
|
|
||||||
|
// public key in RAW format
|
||||||
|
n_in.put(Util.h2b(
|
||||||
|
"aff5f9e2e2622320d44dbf54f2274a0f96fa7d70a63ddaa563f48811"
|
||||||
|
+ "43112bb3c36fe65ba0c9ad99d6fb6e53cb08e3938ee415b3a8cb"
|
||||||
|
+ "7f9602f2154fab83dd160fa6f509ba2c41295af9eea8787d333e"
|
||||||
|
+ "961461447fc60b3c61616ef5b94e822114e6fad44d1f2c476bc2"
|
||||||
|
+ "3bc03609e2e70a483d826409fdb7c50a91269a773976ef137e7f"
|
||||||
|
+ "a477c3951e8fbcb48f2378aa5e430e8c60b481beeb63df9abe10"
|
||||||
|
+ "c7ccf266e394fbd925e8725e4675fb6ad895caed4b31d751c871"
|
||||||
|
+ "2533e1c42ebefe9166e1aa20631521858c7548c61626ede105f2"
|
||||||
|
+ "812632bac96eb769c9be560beef4200b86409727a5a61d1cc583"
|
||||||
|
+ "1785ba4d42f02dd298a56bbbd6c479ce724d5bb5"))
|
||||||
|
.rewind();
|
||||||
|
e_in.put(Util.h2b("d0ee61")).rewind();
|
||||||
|
|
||||||
|
// import public key from RAW format
|
||||||
|
key.decodeRawPublicKey(n_in, e_in);
|
||||||
|
// export the public key to a RAW format
|
||||||
|
key.exportRawPublicKey(n_out, e_out);
|
||||||
|
|
||||||
|
if (Arrays.equals(n_in.array(), n_out.array())) {
|
||||||
|
if (Arrays.equals(e_in.array(), e_out.array())) {
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean publicKeyDecodeAndEncodeWithByteArray() {
|
||||||
|
boolean retVal = false;
|
||||||
|
Rsa key = new Rsa();
|
||||||
|
|
||||||
|
byte[] n_in = Util.h2b(
|
||||||
|
"aff5f9e2e2622320d44dbf54f2274a0f96fa7d70a63ddaa563f48811"
|
||||||
|
+ "43112bb3c36fe65ba0c9ad99d6fb6e53cb08e3938ee415b3a8cb"
|
||||||
|
+ "7f9602f2154fab83dd160fa6f509ba2c41295af9eea8787d333e"
|
||||||
|
+ "961461447fc60b3c61616ef5b94e822114e6fad44d1f2c476bc2"
|
||||||
|
+ "3bc03609e2e70a483d826409fdb7c50a91269a773976ef137e7f"
|
||||||
|
+ "a477c3951e8fbcb48f2378aa5e430e8c60b481beeb63df9abe10"
|
||||||
|
+ "c7ccf266e394fbd925e8725e4675fb6ad895caed4b31d751c871"
|
||||||
|
+ "2533e1c42ebefe9166e1aa20631521858c7548c61626ede105f2"
|
||||||
|
+ "812632bac96eb769c9be560beef4200b86409727a5a61d1cc583"
|
||||||
|
+ "1785ba4d42f02dd298a56bbbd6c479ce724d5bb5");
|
||||||
|
byte[] e_in = Util.h2b("d0ee61");
|
||||||
|
byte[] n_out = new byte[n_in.length];
|
||||||
|
byte[] e_out = new byte[e_in.length];
|
||||||
|
long[] n_len = new long[1];
|
||||||
|
long[] e_len = new long[1];
|
||||||
|
|
||||||
|
n_len[0] = n_out.length;
|
||||||
|
e_len[0] = e_out.length;
|
||||||
|
|
||||||
|
key.decodeRawPublicKey(n_in, e_in);
|
||||||
|
key.exportRawPublicKey(n_out, n_len, e_out, e_len);
|
||||||
|
|
||||||
|
if (Arrays.equals(n_in, n_out)) {
|
||||||
|
if (Arrays.equals(e_in, e_out)) {
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean rsaOperations() {
|
||||||
|
boolean retVal = false;
|
||||||
|
// "private key" in DER format, but I know it includes both keys
|
||||||
|
Rsa priv = new Rsa(Util.h2b(
|
||||||
|
"308204a40201000282010100c303d12bfe39a432453b53c8842b2a7c"
|
||||||
|
+ "749abdaa2a520747d6a636b207328ed0ba697bc6c3449ed48148"
|
||||||
|
+ "fd2d68a28b67bba175c8362c4ad21bf78bbacf0df9efecf1811e"
|
||||||
|
+ "7b9b03479abf65cc7f652469a6e814895be434f7c5b01493f567"
|
||||||
|
+ "7b3a7a78e101565691a613428dd23c409c4cefd186df37511b0c"
|
||||||
|
+ "a13bf5f1a34a35e4e1ce96df1b7ebf4e97d010e8a8083081af20"
|
||||||
|
+ "0b4314c57467b432826f8d86c28840993683ba1e40722217d752"
|
||||||
|
+ "652473b0ceef19cdaeff786c7bc01203d44e720d506d3ba33ba3"
|
||||||
|
+ "995e9dc8d90c85b3d98ad95426db6dfaacbbff254cc4d179f471"
|
||||||
|
+ "d386401813b063b5724e30c49784862d562fd715f77fc0aef5fc"
|
||||||
|
+ "5be5fba1bad302030100010282010100a2e6d85f107164089e2e"
|
||||||
|
+ "6dd16d1e85d20ab18c47ce2c516aa0129e53de914c1d6dea597b"
|
||||||
|
+ "f277aad9c6d98aabd8e116e46326ffb56c1359b8e3a5c872172e"
|
||||||
|
+ "0c9f6fe5593f766f49b111c25a2e16290ddeb78edc40d5a2eee0"
|
||||||
|
+ "1ea1f4be97db86639614cd9809602d30769c3ccde688ee479279"
|
||||||
|
+ "0b5a00e25e5f117c7df908b72006892a5dfd00ab22e1f0b3bc24"
|
||||||
|
+ "a95e260e1f002dfe219a535b6dd32bab9482684336d8f62fc622"
|
||||||
|
+ "fcb5415d0d3360eaa47d7ee84b559156d35c578f1f94172faade"
|
||||||
|
+ "e99ea8f4cf8a4c8ea0e45673b2cf4f86c5693cf324208b5c960c"
|
||||||
|
+ "fa6b123b9a67c1dfc696b2a5d5920d9b094268241045d450e417"
|
||||||
|
+ "3948d0358b946d11de8fca5902818100ea24a7f96933e971dc52"
|
||||||
|
+ "7d8821282f49deba7216e9cc477a880d94578458163a81b03fa2"
|
||||||
|
+ "cfa66c1eb00629008fe77776acdbcac7d95e9b3f269052aefc38"
|
||||||
|
+ "900014bbb40f5894e72f6a7e1c4f4121d431591f4e8a1a8da757"
|
||||||
|
+ "6c22d8e5f47e32a610cb64a5550387a627058cc3d7b627b24dba"
|
||||||
|
+ "30da478f54d33d8b848d949858a502818100d5381bc38fc5930c"
|
||||||
|
+ "470b6f3592c5b08d46c892188ff5800af7efa1fe80b9b52abaca"
|
||||||
|
+ "18b05da507d0938dd89c041cd4628ea6268101ffce8a2a633435"
|
||||||
|
+ "40aa6d80de89236a574d9e6ead934e56900b6d9d738b0cae273d"
|
||||||
|
+ "de4ef0aac56c78676c94529c37676c2defbbafdfa6903cc447cf"
|
||||||
|
+ "8d969e98a9b49fc5a650dcb3f0fb74170281805e830962bdba7c"
|
||||||
|
+ "a2bf4274f57c1cd269c9040d857e3e3d2412c3187bf329f35f0e"
|
||||||
|
+ "766c5975e44184699d32f3cd22abb035ba4ab23ce5d958b6624f"
|
||||||
|
+ "5ddee59e0aca53b22cf79eb36b0a5b7965ec6e914e9220f6fcfc"
|
||||||
|
+ "16edd3760ce2ec7fb269136b780e5a4664b45eb725a05a753a4b"
|
||||||
|
+ "efc73c3ef7fd26b820c4990a9a73bec31902818100ba449314ac"
|
||||||
|
+ "34193b5f9160acf7b4d681053651533de865dcaf2edc613ec97d"
|
||||||
|
+ "b87f87f03b9b03822937ce724e11d5b1c10c07a099914a8d7fec"
|
||||||
|
+ "79cff139b5e985ec62f7da7dbc644d223c0ef2d651f587d899c0"
|
||||||
|
+ "11205d0f29fd5be2aed91cd921566dfc84d05fed10151c1821e7"
|
||||||
|
+ "c43d4bd7d09e6a95cf22c9037b9ee36001fc2f02818011d04bcf"
|
||||||
|
+ "1b67b99f1075478665ae31c2c630ac590650d90fb57006f7f0d3"
|
||||||
|
+ "c8627ca8da6ef6213fd37f5fea8aab3fd92a5ef351d2c23037e3"
|
||||||
|
+ "2da3750d1e4d2134d557705c89bf72ec4a6e68d5cd1874334e8c"
|
||||||
|
+ "3a458fe69640eb63f919863a51dd894bb0f3f99f5d289538be35"
|
||||||
|
+ "abca5ce7935334a1455d1339654246a19fcdf5bf"));
|
||||||
|
|
||||||
|
byte[] n_out = new byte[256];
|
||||||
|
byte[] e_out = new byte[3];
|
||||||
|
long[] n_len = new long[1];
|
||||||
|
long[] e_len = new long[1];
|
||||||
|
n_len[0] = n_out.length;
|
||||||
|
e_len[0] = e_out.length;
|
||||||
|
|
||||||
|
priv.exportRawPublicKey(n_out, n_len, e_out, e_len);
|
||||||
|
priv.setRng(rng);
|
||||||
|
|
||||||
|
Rsa pub = new Rsa(n_out, e_out);
|
||||||
|
|
||||||
|
byte[] plaintext = "Now is the time for all".getBytes();
|
||||||
|
|
||||||
|
byte[] ciphertext = pub.encrypt(plaintext, rng);
|
||||||
|
|
||||||
|
if (Arrays.equals(plaintext, priv.decrypt(ciphertext))) {
|
||||||
|
byte[] signature = priv.sign(plaintext, rng);
|
||||||
|
if (Arrays.equals(plaintext, pub.verify(signature))) {
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// assertArrayEquals(plaintext, priv.decrypt(ciphertext));
|
||||||
|
// assertArrayEquals(plaintext, pub.verify(signature));
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
package io.malloc.ccc.nc;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
|
import com.wolfssl.wolfcrypt.Sha256;
|
||||||
|
|
||||||
|
public class ShaTest {
|
||||||
|
|
||||||
|
private ByteBuffer data = ByteBuffer.allocateDirect(32);
|
||||||
|
private ByteBuffer result = ByteBuffer.allocateDirect(Sha256.DIGEST_SIZE);
|
||||||
|
private ByteBuffer expected = ByteBuffer.allocateDirect(Sha256.DIGEST_SIZE);
|
||||||
|
|
||||||
|
|
||||||
|
public void hashShouldMatchUsingByteBuffer() throws ShortBufferException {
|
||||||
|
String[] dataVector = new String[] {
|
||||||
|
"",
|
||||||
|
"8bf43fbc59b1cefb",
|
||||||
|
"68596a39b6b1dbbce92983d0c87811f9",
|
||||||
|
"695f0bcfd8b1799a7519c182c55baaffe66a664ac5d06ad7",
|
||||||
|
"b9c325ed83e582d315a03d191d3a99c5178d1a1dc4aa9669d8c28ffaf347c06b" };
|
||||||
|
String[] hashVector = new String[] {
|
||||||
|
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||||
|
"47291036995e041cd53d640190002ab9b56fec8faf647a8df3b278fe445ab05e",
|
||||||
|
"041f246778af35809a4e8d06d41ba3e3c73f54050149d13e821e5ca45178e88b",
|
||||||
|
"afa01304f7356d5d946304c7aef0c5190716eeacee6a837edd431906aa50e5ec",
|
||||||
|
"731cf20719a0838dc15a33293ad977855bd28f5d2c768e7c0b632bf65d6c84e0" };
|
||||||
|
|
||||||
|
for (int i = 0; i < dataVector.length; i++) {
|
||||||
|
Sha256 sha = new Sha256();
|
||||||
|
|
||||||
|
data.put(Util.h2b(dataVector[i])).rewind();
|
||||||
|
expected.put(Util.h2b(hashVector[i])).rewind();
|
||||||
|
|
||||||
|
sha.update(data, dataVector[i].length() / 2);
|
||||||
|
sha.digest(result);
|
||||||
|
|
||||||
|
outputStr(expected.array(), result.array());
|
||||||
|
data.rewind();
|
||||||
|
result.rewind();
|
||||||
|
// assertEquals(expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hashShouldMatchUsingByteArray() {
|
||||||
|
String[] dataVector = new String[] { "", "8bf43fbc59b1cefb",
|
||||||
|
"68596a39b6b1dbbce92983d0c87811f9",
|
||||||
|
"695f0bcfd8b1799a7519c182c55baaffe66a664ac5d06ad7",
|
||||||
|
"b9c325ed83e582d315a03d191d3a99c5178d1a1dc4aa9669d8c28ffaf347c06b" };
|
||||||
|
String[] hashVector = new String[] {
|
||||||
|
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||||
|
"47291036995e041cd53d640190002ab9b56fec8faf647a8df3b278fe445ab05e",
|
||||||
|
"041f246778af35809a4e8d06d41ba3e3c73f54050149d13e821e5ca45178e88b",
|
||||||
|
"afa01304f7356d5d946304c7aef0c5190716eeacee6a837edd431906aa50e5ec",
|
||||||
|
"731cf20719a0838dc15a33293ad977855bd28f5d2c768e7c0b632bf65d6c84e0" };
|
||||||
|
|
||||||
|
for (int i = 0; i < dataVector.length; i++) {
|
||||||
|
Sha256 sha = new Sha256();
|
||||||
|
|
||||||
|
byte[] data = Util.h2b(dataVector[i]);
|
||||||
|
byte[] expected = Util.h2b(hashVector[i]);
|
||||||
|
|
||||||
|
sha.update(data);
|
||||||
|
byte[] result = sha.digest();
|
||||||
|
outputStr(expected, result);
|
||||||
|
// assertArrayEquals(expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void outputStr(byte[] cmp1, byte[] cmp2) {
|
||||||
|
if ( Arrays.equals(cmp1, cmp2) ) {
|
||||||
|
System.out.println("J3G_YAY: SHA256 function working!!");
|
||||||
|
System.out.println("J3G_YAY: "+Util.b2h(expected.array())+"=="+Util.b2h(result.array()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("J3G_ERR: SHA256 error");
|
||||||
|
System.out.println("J3G_ERR: " + Util.b2h(expected.array()) + "==" + Util.b2h(result.array()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
package io.malloc.ccc.nc;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public static byte[] h2b(String s) {
|
||||||
|
int len = s.length();
|
||||||
|
byte[] data = new byte[len / 2];
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i += 2) {
|
||||||
|
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character
|
||||||
|
.digit(s.charAt(i + 1), 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||||
|
|
||||||
|
public static String b2h(byte[] bytes) {
|
||||||
|
char[] hexChars = new char[bytes.length * 2];
|
||||||
|
|
||||||
|
for (int j = 0; j < bytes.length; j++) {
|
||||||
|
int v = bytes[j] & 0xFF;
|
||||||
|
hexChars[j * 2] = hexArray[v >>> 4];
|
||||||
|
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(hexChars);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||||
|
<orderEntry type="library" name="Flutter Plugins" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,161 @@
|
||||||
|
group 'com.companyname.artifactname'
|
||||||
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// THIS goes in the root build.gradle
|
||||||
|
//
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
// put first to pull here first
|
||||||
|
mavenLocal()
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
maven {
|
||||||
|
url "https://maven.google.com" // Google's Maven repository
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
// put first to pull here first
|
||||||
|
mavenLocal()
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
maven {
|
||||||
|
url "https://maven.google.com" // Google's Maven repository
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// THIS goes in APP specific build.gradle
|
||||||
|
//
|
||||||
|
apply plugin: 'com.android.library'
|
||||||
|
android {
|
||||||
|
compileSdkVersion 28
|
||||||
|
buildToolsVersion '28.0.3'
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 23
|
||||||
|
targetSdkVersion 28
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.1"
|
||||||
|
}
|
||||||
|
lintOptions {
|
||||||
|
abortOnError false
|
||||||
|
}
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
compile 'com.android.support:appcompat-v7:23.2.1'
|
||||||
|
compile 'com.android.support:support-v4:23.2.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// pull in everything from ./libs folder
|
||||||
|
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is the SIMPLE method to publish locally
|
||||||
|
//
|
||||||
|
apply plugin: 'maven-publish'
|
||||||
|
project.afterEvaluate {
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
library(MavenPublication) {
|
||||||
|
groupId 'io.malloc.ccc'
|
||||||
|
artifactId 'nc-jni'
|
||||||
|
version "1.1"
|
||||||
|
artifact(bundleReleaseAar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// more complicated example (gen the XML explicitly)
|
||||||
|
project.afterEvaluate {
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
mavenDebugAAR(MavenPublication) {
|
||||||
|
artifact bundleDebugAar
|
||||||
|
|
||||||
|
pom.withXml {
|
||||||
|
def dependenciesNode = asNode().appendNode('dependencies')
|
||||||
|
configurations.api.allDependencies.each { ModuleDependency dp ->
|
||||||
|
def dependencyNode = dependenciesNode.appendNode('dependency')
|
||||||
|
dependencyNode.appendNode('groupId', dp.group)
|
||||||
|
dependencyNode.appendNode('artifactId', dp.name)
|
||||||
|
dependencyNode.appendNode('version', dp.version)
|
||||||
|
|
||||||
|
if (dp.excludeRules.size() > 0) {
|
||||||
|
def exclusions = dependencyNode.appendNode('exclusions')
|
||||||
|
dp.excludeRules.each { ExcludeRule ex ->
|
||||||
|
def exclusion = exclusions.appendNode('exclusion')
|
||||||
|
exclusion.appendNode('groupId', ex.group)
|
||||||
|
exclusion.appendNode('artifactId', ex.module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mavenReleaseAAR(MavenPublication) {
|
||||||
|
artifact bundleReleaseAar
|
||||||
|
|
||||||
|
pom.withXml {
|
||||||
|
def dependenciesNode = asNode().appendNode('dependencies')
|
||||||
|
configurations.api.allDependencies.each { ModuleDependency dp ->
|
||||||
|
def dependencyNode = dependenciesNode.appendNode('dependency')
|
||||||
|
dependencyNode.appendNode('groupId', dp.group)
|
||||||
|
dependencyNode.appendNode('artifactId', dp.name)
|
||||||
|
dependencyNode.appendNode('version', dp.version)
|
||||||
|
|
||||||
|
if (dp.excludeRules.size() > 0) {
|
||||||
|
def exclusions = dependencyNode.appendNode('exclusions')
|
||||||
|
dp.excludeRules.each { ExcludeRule ex ->
|
||||||
|
def exclusion = exclusions.appendNode('exclusion')
|
||||||
|
exclusion.appendNode('groupId', ex.group)
|
||||||
|
exclusion.appendNode('artifactId', ex.module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
|
||||||
|
maven {
|
||||||
|
name 'nexusSnapshot'
|
||||||
|
credentials {
|
||||||
|
username '<User with deployment rights>'
|
||||||
|
password '<User password>'
|
||||||
|
}
|
||||||
|
url '<URL to nexus>'
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
name 'nexusRelease'
|
||||||
|
credentials {
|
||||||
|
username '<User with deployment rights>'
|
||||||
|
password '<User password>'
|
||||||
|
}
|
||||||
|
url '<URL to nexus>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
===========
|
||||||
|
Flutter ffi
|
||||||
|
===========
|
||||||
|
|
||||||
|
|
||||||
|
dart:ffi
|
||||||
|
--------
|
||||||
|
* SQLite mini tutorial
|
||||||
|
- foreign function interface "dart:ffi"
|
||||||
|
- invokes C functions from navive SQLite library
|
||||||
|
- https://github.com/dart-lang/sdk/blob/master/samples/ffi/sqlite/docs/sqlite-tutorial.md
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
=====================
|
||||||
|
Create Flutter Plugin
|
||||||
|
=====================
|
||||||
|
|
||||||
|
* https://flutter.dev/docs/development/platform-integration/platform-channels#codec
|
||||||
|
|
||||||
|
From flutter.dev:
|
||||||
|
**"some specific steps are needed to ensure a smooth experience"**
|
||||||
|
|
||||||
|
|
||||||
|
SOURCE CODE
|
||||||
|
===========
|
||||||
|
|
||||||
|
Plugin Implementation
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Init Project
|
||||||
|
------------
|
||||||
|
|
||||||
|
Generate Project:
|
||||||
|
::
|
||||||
|
|
||||||
|
# generate flutter plugin project
|
||||||
|
$ flutter create --org io.malloc.ccc --template=plugin ccipherchain
|
||||||
|
|
||||||
|
# generate with kotlin and swift support
|
||||||
|
$ flutter create --org io.malloc.ccc --template=plugin -i swift -a kotline ccipherchain
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DART plugin code is in: ccc_fplugin/lib/ccc_fplugin.dart
|
||||||
|
JAVA plugin code is in: android/
|
||||||
|
iOS plugin code is in: ios/
|
||||||
|
|
||||||
|
EXAMPLE code is in: ccc_fplugin/example/lib/main.dart
|
||||||
|
$ cd ccc_fplugin/example
|
||||||
|
$ flutter run
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Open Android Java Project to edit:
|
||||||
|
* **OPEN: ./example/android/build.gradle file in Android Studio**
|
||||||
|
* to edit platform code in an IDE see https://flutter.io/developing-packages/#edit-plugin-package.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
=====
|
||||||
|
|
||||||
|
WEB Info
|
||||||
|
--------
|
||||||
|
* FLUTTER
|
||||||
|
- https://flutter.dev/docs/development/packages-and-plugins/developing-packages
|
||||||
|
* Good Example
|
||||||
|
- https://medium.com/flutter-io/writing-a-good-flutter-plugin-1a561b986c9c
|
||||||
|
* How to Open Android Source Code Plugin Lib Inside Flutter Project
|
||||||
|
- https://github.com/flutter/flutter/issues/19830
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ISSUES
|
||||||
|
======
|
||||||
|
|
||||||
|
|
||||||
|
edit ./android && ./example/android
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
**OPEN: ./example/android/build.gradle file in Android Studio**
|
||||||
|
|
||||||
|
the gradle file there also includes the flutter plugin project, which
|
||||||
|
will also cascade to include the android project, etc...VERY convoluted!!
|
||||||
|
BASTARDS!!
|
||||||
|
|
||||||
|
* Flutter Trouble Tickets
|
||||||
|
- https://github.com/flutter/flutter/issues/19830
|
||||||
|
- https://github.com/flutter/flutter/issues/11632
|
||||||
|
- https://github.com/flutter/flutter/issues/9698
|
||||||
|
|
||||||
|
* --or-- add flutter.jar to the project
|
||||||
|
- j3g/apps/flutter/bin/cache/artifacts/engine/android-x64/flutter.jar
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MISC
|
||||||
|
====
|
||||||
|
::
|
||||||
|
|
||||||
|
Host platform code is in the "android" and "ios" directories under ccc_fplugin.
|
||||||
|
To edit platform code in an IDE see https://flutter.io/developing-packages/#edit-plugin-package.
|
||||||
|
|
||||||
|
ISSUE -->
|
||||||
|
android: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#step-2b-add-android-platform-code-javakt
|
||||||
|
ios: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#step-2c-add-ios-platform-code-hmswift
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
===================
|
||||||
|
Flutter Plugin Bugs
|
||||||
|
===================
|
||||||
|
|
||||||
|
|
||||||
|
.aar android library issues fsck'n flutter
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
Flutter has a lot of cascading gradle build files and they are using black magic to get things workings. For example
|
||||||
|
it is difficult to code for the flutter plugin because of all the gradle build depedencies. You cannot use another
|
||||||
|
gradle file in the android project that is part of the plugin. So either add the library in ./libs or add it to Maven...
|
||||||
|
either Maven local or Maven remote.
|
||||||
|
|
||||||
|
mavenLocal():
|
||||||
|
* ISSUES: with using gradle to add the nextcrypto library "wolfssl-jni.aar"
|
||||||
|
- FIX: use ./libs/ locally pulled in by "implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])"
|
||||||
|
- FIX: use mavenLocal() and store in ~.m2/... pull using "implementation 'io.malloc.ccc:nc-jni:1.1@aar'"
|
||||||
|
|
||||||
|
* Solution
|
||||||
|
- https://stackoverflow.com/questions/50971022/how-to-use-local-aar-inside-flutter-plugin
|
||||||
|
|
||||||
|
* No solutions
|
||||||
|
- https://stackoverflow.com/questions/55475576/add-plain-android-library-to-a-flutter-plugin
|
||||||
|
- https://stackoverflow.com/questions/55005818/how-do-i-add-library-module-dependency-to-a-flutter-plugins-android-folder-corr
|
||||||
|
|
||||||
|
* for examples see
|
||||||
|
- --> dev_maven.rst
|
||||||
|
- --> build_mavenLocal.gradle
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.aar library bugs after ./libs and mavenLocal()
|
||||||
|
-----------------------------------------------
|
||||||
|
|
||||||
|
It is interesting that it "merges" the AndroidManifest.xml files. I did some reading and I discovered
|
||||||
|
that all the resources within the library (.aar) are public. Therefore collisions will happen. So the
|
||||||
|
string property of "@string/app_name" was colliding because it was defined twice. So after removing all
|
||||||
|
resources (./src/main/res/..) from the library project ("wolfssl-jni"), then removed all stuff within the
|
||||||
|
libraries AndroidManifest.xml file too...because of the merging. So with all resources removed and the
|
||||||
|
AndroidManifest.xml cleaned...there will be no collisions.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
> Task :app:processDebugManifest FAILED
|
||||||
|
/Volumes/malloc-dev/nextcrypto/source/nc-ww/app/ccc_fplugin/example/android/app/src/debug/AndroidManifest.xml:11:9-44 Error:
|
||||||
|
Attribute application@label value=(ccc_fplugin_example) from AndroidManifest.xml:11:9-44
|
||||||
|
is also present at [wolfssl-jni.aar] AndroidManifest.xml:13:9-41 value=(@string/app_name).
|
||||||
|
Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:9:5-32:19 to override.
|
||||||
|
/Volumes/malloc-dev/nextcrypto/source/nc-ww/app/ccc_fplugin/example/android/app/src/debug/AndroidManifest.xml Error:
|
||||||
|
uses-sdk:minSdkVersion 16 cannot be smaller than version 23 declared in library [wolfssl-jni.aar] /Users/j3g/.gradle/caches/transforms-2/files-2.1/d60f1db6c5cf298a03f176d7f25dc8f6/AndroidManifest.xml as the library might be using APIs not available in 16
|
||||||
|
Suggestion: use a compatible library with a minSdk of at most 16,
|
||||||
|
or increase this project's minSdk version to at least 23,
|
||||||
|
or use tools:overrideLibrary="io.malloc.ccc" to force usage (may lead to runtime failures)
|
||||||
|
|
||||||
|
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
|
||||||
|
|
||||||
|
10 actionable tasks: 1 executed, 9 up-to-date
|
||||||
|
ERROR: Manifest merger failed with multiple errors, see logs
|
||||||
|
|
||||||
|
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
|
||||||
|
It will be removed at the end of 2019.
|
||||||
|
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
|
||||||
|
To determine what is calling variantOutput.getProcessResources(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
|
||||||
|
Affected Modules: app
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
=====
|
||||||
|
Maven
|
||||||
|
=====
|
||||||
|
|
||||||
|
* https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02
|
||||||
|
* https://android.jlelse.eu/android-local-libraries-with-maven-b7456d4268cf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Maven Local (publishToMavenLocal)
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
STEP 1:
|
||||||
|
* push to maven local
|
||||||
|
- ADD: "mavenLocal()" to --> root/main build.gradle
|
||||||
|
- make sure it is first in the list
|
||||||
|
- EXE: $ ./gradlew publishToMavenLocal
|
||||||
|
|
||||||
|
STEP 2:
|
||||||
|
* pull from maven local
|
||||||
|
- ADD: "mavenLocal()" to build.gradle
|
||||||
|
- ADD: implementation 'com.companyname.artifactname:libraryname:1.1@aar'
|
||||||
|
- ADD: implementation 'io.malloc.ccc:nc-jni:1.1@aar'
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
# push the .jar/.aar to ~/.m2/
|
||||||
|
$ gradle publishToMavenLocal
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is root build.gradle
|
||||||
|
//
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is app LIBRARY project build.gradle
|
||||||
|
//
|
||||||
|
|
||||||
|
// we are going to "publish" to local maven repository
|
||||||
|
apply plugin: 'maven-publish'
|
||||||
|
project.afterEvaluate {
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
library(MavenPublication) {
|
||||||
|
groupId 'io.malloc.ccc'
|
||||||
|
artifactId 'nc-jni'
|
||||||
|
version "1.1"
|
||||||
|
artifact(bundleReleaseAar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is app project build.gradle
|
||||||
|
//
|
||||||
|
|
||||||
|
implementation 'com.companyname.artifactname:libraryname:1.1@aar'
|
||||||
|
implementation 'io.malloc.ccc:nc-jni:1.1@aar'
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
.idea/
|
||||||
|
.vagrant/
|
||||||
|
.sconsign.dblite
|
||||||
|
.svn/
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
*.swp
|
||||||
|
profile
|
||||||
|
|
||||||
|
DerivedData/
|
||||||
|
build/
|
||||||
|
GeneratedPluginRegistrant.h
|
||||||
|
GeneratedPluginRegistrant.m
|
||||||
|
|
||||||
|
.generated/
|
||||||
|
|
||||||
|
*.pbxuser
|
||||||
|
*.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
*.perspectivev3
|
||||||
|
|
||||||
|
!default.pbxuser
|
||||||
|
!default.mode1v3
|
||||||
|
!default.mode2v3
|
||||||
|
!default.perspectivev3
|
||||||
|
|
||||||
|
xcuserdata
|
||||||
|
|
||||||
|
*.moved-aside
|
||||||
|
|
||||||
|
*.pyc
|
||||||
|
*sync/
|
||||||
|
Icon?
|
||||||
|
.tags*
|
||||||
|
|
||||||
|
/Flutter/Generated.xcconfig
|
|
@ -0,0 +1,4 @@
|
||||||
|
#import <Flutter/Flutter.h>
|
||||||
|
|
||||||
|
@interface CccFpluginPlugin : NSObject<FlutterPlugin>
|
||||||
|
@end
|
|
@ -0,0 +1,20 @@
|
||||||
|
#import "CccFpluginPlugin.h"
|
||||||
|
|
||||||
|
@implementation CccFpluginPlugin
|
||||||
|
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||||
|
FlutterMethodChannel* channel = [FlutterMethodChannel
|
||||||
|
methodChannelWithName:@"ccc_fplugin"
|
||||||
|
binaryMessenger:[registrar messenger]];
|
||||||
|
CccFpluginPlugin* instance = [[CccFpluginPlugin alloc] init];
|
||||||
|
[registrar addMethodCallDelegate:instance channel:channel];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||||
|
if ([@"getPlatformVersion" isEqualToString:call.method]) {
|
||||||
|
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
|
||||||
|
} else {
|
||||||
|
result(FlutterMethodNotImplemented);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -0,0 +1,21 @@
|
||||||
|
#
|
||||||
|
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
|
||||||
|
#
|
||||||
|
Pod::Spec.new do |s|
|
||||||
|
s.name = 'ccc_fplugin'
|
||||||
|
s.version = '0.0.1'
|
||||||
|
s.summary = 'A new flutter plugin project.'
|
||||||
|
s.description = <<-DESC
|
||||||
|
A new flutter plugin project.
|
||||||
|
DESC
|
||||||
|
s.homepage = 'http://example.com'
|
||||||
|
s.license = { :file => '../LICENSE' }
|
||||||
|
s.author = { 'Your Company' => 'email@example.com' }
|
||||||
|
s.source = { :path => '.' }
|
||||||
|
s.source_files = 'Classes/**/*'
|
||||||
|
s.public_header_files = 'Classes/**/*.h'
|
||||||
|
s.dependency 'Flutter'
|
||||||
|
|
||||||
|
s.ios.deployment_target = '8.0'
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class CccFplugin {
|
||||||
|
static const MethodChannel _channel = const MethodChannel('ccc_fplugin');
|
||||||
|
|
||||||
|
static Future<String> get platformVersion async {
|
||||||
|
final String version = await _channel.invokeMethod('getPlatformVersion');
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> aesTest() async {
|
||||||
|
await _channel.invokeMethod('aesTest');
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<Uint8List> aesEnc(Uint8List iv, Uint8List key, String pText) async {
|
||||||
|
final Uint8List eData = await _channel.invokeMethod('aesEnc', {"iv":iv, "key":key, "pText":pText});
|
||||||
|
return eData;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<Uint8List> aesEncUint(Uint8List iv, Uint8List key, Uint8List pData) async {
|
||||||
|
final Uint8List eData = await _channel.invokeMethod('aesEncUint', {"iv":iv, "key":key, "pData":pData});
|
||||||
|
return eData;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<Uint8List> aesDec(Uint8List iv, Uint8List key, Uint8List cData) async {
|
||||||
|
final Uint8List pData = await _channel.invokeMethod('aesDec', {"iv":iv, "key":key, "cData":cData});
|
||||||
|
return pData;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
import "dart:convert";
|
||||||
|
import "dart:typed_data";
|
||||||
|
|
||||||
|
const String _ALPHABET = "0123456789abcdef";
|
||||||
|
|
||||||
|
/// An instance of the default implementation of the [HexCodec].
|
||||||
|
const HEX = const HexCodec();
|
||||||
|
|
||||||
|
/// A codec for encoding and decoding byte arrays to and from
|
||||||
|
/// hexadecimal strings.
|
||||||
|
class HexCodec extends Codec<List<int>, String> {
|
||||||
|
|
||||||
|
const HexCodec();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Converter<List<int>, String> get encoder => const HexEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Converter<String, List<int>> get decoder => const HexDecoder();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A converter to encode byte arrays into hexadecimal strings.
|
||||||
|
class HexEncoder extends Converter<List<int>, String> {
|
||||||
|
|
||||||
|
/// If true, the encoder will encode into uppercase hexadecimal strings.
|
||||||
|
final bool upperCase;
|
||||||
|
|
||||||
|
const HexEncoder({this.upperCase: false});
|
||||||
|
|
||||||
|
@override
|
||||||
|
String convert(List<int> bytes) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
for (int part in bytes) {
|
||||||
|
if (part & 0xff != part) {
|
||||||
|
throw new FormatException("Non-byte integer detected");
|
||||||
|
}
|
||||||
|
buffer.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}');
|
||||||
|
}
|
||||||
|
if(upperCase) {
|
||||||
|
return buffer.toString().toUpperCase();
|
||||||
|
} else {
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A converter to decode hexadecimal strings into byte arrays.
|
||||||
|
class HexDecoder extends Converter<String, List<int>> {
|
||||||
|
|
||||||
|
const HexDecoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<int> convert(String hex) {
|
||||||
|
String str = hex.replaceAll(" ", "");
|
||||||
|
str = str.toLowerCase();
|
||||||
|
if(str.length % 2 != 0) {
|
||||||
|
str = "0" + str;
|
||||||
|
}
|
||||||
|
Uint8List result = new Uint8List(str.length ~/ 2);
|
||||||
|
for(int i = 0 ; i < result.length ; i++) {
|
||||||
|
int firstDigit = _ALPHABET.indexOf(str[i*2]);
|
||||||
|
int secondDigit = _ALPHABET.indexOf(str[i*2+1]);
|
||||||
|
if (firstDigit == -1 || secondDigit == -1) {
|
||||||
|
throw new FormatException("Non-hex character detected in $hex");
|
||||||
|
}
|
||||||
|
result[i] = (firstDigit << 4) + secondDigit;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
name: ccc_fplugin
|
||||||
|
description: Copius Cipher Chain Plugin
|
||||||
|
version: 0.0.1
|
||||||
|
author: cto@malloc.io
|
||||||
|
homepage:
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: ">=2.1.0 <3.0.0"
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
|
flutter:
|
||||||
|
plugin:
|
||||||
|
androidPackage: io.malloc.ccc.ccc_fplugin
|
||||||
|
pluginClass: CccFpluginPlugin
|
|
@ -0,0 +1,21 @@
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:ccc_fplugin/ccc_fplugin.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
const MethodChannel channel = MethodChannel('ccc_fplugin');
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
channel.setMockMethodCallHandler((MethodCall methodCall) async {
|
||||||
|
return '42';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
channel.setMockMethodCallHandler(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getPlatformVersion', () async {
|
||||||
|
expect(await CccFplugin.platformVersion, '42');
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue