曹衍涛
5 years ago
21 changed files with 51376 additions and 213 deletions
Binary file not shown.
@ -0,0 +1,27 @@
|
||||
fileFormatVersion: 2 |
||||
guid: da0bf7a94e580244db6a56c2d1003035 |
||||
PluginImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
defineConstraints: [] |
||||
isPreloaded: 0 |
||||
isOverridable: 0 |
||||
isExplicitlyReferenced: 0 |
||||
validateReferences: 1 |
||||
platformData: |
||||
- first: |
||||
Any: |
||||
second: |
||||
enabled: 1 |
||||
settings: {} |
||||
- first: |
||||
Editor: Editor |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
DefaultValueInitialized: true |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Binary file not shown.
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2 |
||||
guid: cdf3ee719a2abba4c9b38b4758a741be |
||||
PluginImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
defineConstraints: [] |
||||
isPreloaded: 0 |
||||
isOverridable: 0 |
||||
isExplicitlyReferenced: 0 |
||||
validateReferences: 1 |
||||
platformData: |
||||
- first: |
||||
Any: |
||||
second: |
||||
enabled: 1 |
||||
settings: {} |
||||
- first: |
||||
Editor: Editor |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
DefaultValueInitialized: true |
||||
- first: |
||||
Windows Store Apps: WindowsStoreApps |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: AnyCPU |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 88c53133b99c69142a5753f74ffb4bda |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Binary file not shown.
@ -0,0 +1,136 @@
|
||||
fileFormatVersion: 2 |
||||
guid: b4224153725ef6e468efeab33ad7e553 |
||||
timeCreated: 1515718354 |
||||
licenseType: Pro |
||||
PluginImporter: |
||||
serializedVersion: 2 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
isPreloaded: 0 |
||||
isOverridable: 0 |
||||
platformData: |
||||
data: |
||||
first: |
||||
'': Any |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
Exclude Android: 0 |
||||
Exclude Editor: 1 |
||||
Exclude Linux: 1 |
||||
Exclude Linux64: 1 |
||||
Exclude LinuxUniversal: 1 |
||||
Exclude OSXIntel: 1 |
||||
Exclude OSXIntel64: 1 |
||||
Exclude OSXUniversal: 1 |
||||
Exclude WebGL: 0 |
||||
Exclude Win: 1 |
||||
Exclude Win64: 1 |
||||
data: |
||||
first: |
||||
'': Editor |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: AnyCPU |
||||
OS: Windows |
||||
data: |
||||
first: |
||||
Android: Android |
||||
second: |
||||
enabled: 1 |
||||
settings: |
||||
CPU: ARMv7 |
||||
data: |
||||
first: |
||||
Any: |
||||
second: |
||||
enabled: 1 |
||||
settings: {} |
||||
data: |
||||
first: |
||||
Editor: Editor |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: x86_64 |
||||
DefaultValueInitialized: true |
||||
data: |
||||
first: |
||||
Facebook: Win |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: AnyCPU |
||||
data: |
||||
first: |
||||
Facebook: Win64 |
||||
second: |
||||
enabled: 1 |
||||
settings: |
||||
CPU: AnyCPU |
||||
data: |
||||
first: |
||||
Standalone: Linux |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: None |
||||
data: |
||||
first: |
||||
Standalone: Linux64 |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: x86_64 |
||||
data: |
||||
first: |
||||
Standalone: LinuxUniversal |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: None |
||||
data: |
||||
first: |
||||
Standalone: OSXIntel |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: None |
||||
data: |
||||
first: |
||||
Standalone: OSXIntel64 |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: AnyCPU |
||||
data: |
||||
first: |
||||
Standalone: OSXUniversal |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: None |
||||
data: |
||||
first: |
||||
Standalone: Win |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: AnyCPU |
||||
data: |
||||
first: |
||||
Standalone: Win64 |
||||
second: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: AnyCPU |
||||
data: |
||||
first: |
||||
WebGL: WebGL |
||||
second: |
||||
enabled: 1 |
||||
settings: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 8d4d02723bd45a948948827aac26d3ea |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,275 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace SmartX1Demo |
||||
{ |
||||
public class SmartApp |
||||
{ |
||||
bool _is64ibt = false; |
||||
public SmartApp() |
||||
{ |
||||
if (IntPtr.Size == 4) |
||||
_is64ibt = true; |
||||
} |
||||
public int SmartX1Find(string appID, int[] keyHandles, int[] keyNumber) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1Find(appID, keyHandles, keyNumber); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1Find(appID, keyHandles, keyNumber); |
||||
} |
||||
} |
||||
|
||||
//open |
||||
|
||||
public int SmartX1Open(int keyHandle, int uPin1, int uPin2, int uPin3, int uPin4) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4); |
||||
} |
||||
} |
||||
//close |
||||
|
||||
|
||||
public int SmartX1Close(int keyHandle) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1Close(keyHandle); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1Close(keyHandle); |
||||
} |
||||
} |
||||
//checkExist |
||||
|
||||
|
||||
public int SmartX1CheckExist(int keyHandle) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1CheckExist(keyHandle); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1CheckExist(keyHandle); |
||||
} |
||||
} |
||||
//getUid |
||||
|
||||
public int SmartX1GetUid(int keyHandle, StringBuilder uid) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1GetUid(keyHandle, uid); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1GetUid(keyHandle, uid); |
||||
} |
||||
} |
||||
//ReadStorage |
||||
|
||||
public int SmartX1ReadStorage(int keyHandle, int startAddr, int length, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1ReadStorage(keyHandle, startAddr, length, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1ReadStorage(keyHandle, startAddr, length, pBuffer); |
||||
} |
||||
} |
||||
//WriteStorage |
||||
|
||||
public int SmartX1WriteStorage(int keyHandle, int startAddr, int length, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1WriteStorage(keyHandle, startAddr, length, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1WriteStorage(keyHandle, startAddr, length, pBuffer); |
||||
} |
||||
} |
||||
//PageLogin |
||||
|
||||
public int SmartX1PageLogin(int keyHandle, int pageNo, byte[] password, int length) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1PageLogin(keyHandle, pageNo, password, length); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1PageLogin(keyHandle, pageNo, password, length); |
||||
} |
||||
} |
||||
//PageLogout |
||||
|
||||
public int SmartX1PageLogout(int keyHandle, int pageNo) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1PageLogout(keyHandle, pageNo); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1PageLogout(keyHandle, pageNo); |
||||
} |
||||
} |
||||
//ReadPage |
||||
|
||||
public int SmartX1ReadPage(int keyHandle, int pageNo, int startAddr, ref int length, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1ReadPage(keyHandle, pageNo, startAddr, ref length, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1ReadPage(keyHandle, pageNo, startAddr, ref length, pBuffer); |
||||
} |
||||
} |
||||
//WritePage |
||||
|
||||
public int SmartX1WritePage(int keyHandle, int pageNo, int startAddr, int length, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1WritePage(keyHandle, pageNo, startAddr, length, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1WritePage(keyHandle, pageNo, startAddr, length, pBuffer); |
||||
} |
||||
} |
||||
//ReadMem |
||||
|
||||
public int SmartX1ReadMem(int keyHandle, int start, int length, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1ReadMem(keyHandle, start, length, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1ReadMem(keyHandle, start, length, pBuffer); |
||||
} |
||||
} |
||||
//WriteMem |
||||
|
||||
public int SmartX1WriteMem(int keyHandle, int start, int length, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1WriteMem( keyHandle, start, length, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1WriteMem(keyHandle, start, length, pBuffer); |
||||
} |
||||
} |
||||
//encrypt |
||||
|
||||
public int SmartX1TriDesEncrypt(int keyHandle, int buffSize, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1TriDesEncrypt(keyHandle, buffSize, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1TriDesEncrypt(keyHandle, buffSize, pBuffer); |
||||
} |
||||
} |
||||
//desDecrypt |
||||
|
||||
public int SmartX1TriDesDecrypt(int keyHandle, int buffSize, byte[] pBuffer) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1TriDesDecrypt(keyHandle, buffSize, pBuffer); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1TriDesDecrypt(keyHandle, buffSize, pBuffer); |
||||
} |
||||
} |
||||
//led |
||||
|
||||
public int SmartX1Led(int keyHandle, int state) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1Led(keyHandle, state); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1Led(keyHandle, state); |
||||
} |
||||
} |
||||
|
||||
public int SmartX1PageGetProperty(int keyHandle, int pageNo, int propId, int[] propValue) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1PageGetProperty(keyHandle, pageNo, propId, propValue); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1PageGetProperty(keyHandle, pageNo, propId, propValue); |
||||
} |
||||
} |
||||
public int SmartX1GetSoftVersion(int keyHandle, int[] version) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.SmartX1GetSoftVersion(keyHandle, version); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.SmartX1GetSoftVersion(keyHandle, version); |
||||
} |
||||
} |
||||
|
||||
public string TridesEncrypt(string data, string key, Encoding encoding) |
||||
{ |
||||
|
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.TridesEncrypt(data, key, encoding); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.TridesEncrypt(data, key, encoding); |
||||
} |
||||
} |
||||
|
||||
public string TridesDecEncrypt(byte[] data, string key, Encoding encoding) |
||||
{ |
||||
if (_is64ibt) |
||||
{ |
||||
return SmartX1_X86.TridesDecEncrypt(data, key, encoding); |
||||
} |
||||
else |
||||
{ |
||||
return SmartX1_X64.TridesDecEncrypt(data, key, encoding); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 0dd22a80b53a7c942a93255e8d8ecc3a |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,280 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Xml; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
using System.Security.Cryptography; |
||||
using System.Security.Cryptography.Xml; |
||||
using System.Collections; |
||||
|
||||
using SmartX1Demo; |
||||
|
||||
public class SmartController : MonoBehaviour |
||||
{ |
||||
int[] keyHandles = new int[8]; |
||||
int[] keyNumber = new int[8]; |
||||
private int Rtn = 0; |
||||
SmartApp smart = new SmartApp(); |
||||
private bool IsQuit = false; |
||||
|
||||
private DateTime t1, t2, t11; |
||||
void Start() |
||||
{ |
||||
t2 = DateTime.Now; |
||||
t1 = DateTime.Now; |
||||
DontDestroyOnLoad(GameObject.Find("SmartX1")); |
||||
|
||||
tipStyle = new GUIStyle(); |
||||
tipStyle.fontSize = 40; |
||||
tipStyle.normal.textColor = Color.red; |
||||
|
||||
original_filepath = Application.streamingAssetsPath + @"/xml/SmartXProject.xml"; |
||||
encode_filepath = Application.streamingAssetsPath + @"/xml/enSmartXProject.xml"; |
||||
decode_filepath = Application.streamingAssetsPath + @"/xml/deSmartXProject.xml"; |
||||
original_filepath2 = Application.streamingAssetsPath + @"/xml/SmartXProject2.xml"; |
||||
encode_filepath2 = Application.streamingAssetsPath + @"/xml/enSmartXProject2.xml"; |
||||
decode_filepath2 = Application.streamingAssetsPath + @"/xml/deSmartXProject2.xml"; |
||||
|
||||
appid = ControlXML(original_filepath, encode_filepath, decode_filepath); |
||||
appid2 = ControlXML(original_filepath2, encode_filepath2, decode_filepath2); |
||||
//appid = GetAppID(original_filepath); |
||||
|
||||
//检测加密狗是否存在 |
||||
FindSmartX1(); |
||||
} |
||||
string appid = "AXKC"; |
||||
string appid2 = "YuAnguanli"; |
||||
public string GetAppID(string filepath) |
||||
{ |
||||
//filepath = Application.dataPath + @"/xml/SmartXProject.xml"; |
||||
if (File.Exists(filepath)) |
||||
{ |
||||
XmlDocument xmlDoc = new XmlDocument(); |
||||
xmlDoc.Load(filepath); |
||||
XmlNode root = xmlDoc.SelectSingleNode("SmartX1"); |
||||
XmlNodeList nodeList = root.ChildNodes; |
||||
foreach (XmlElement elem in nodeList) |
||||
{ |
||||
if (elem.Name == "BaseInfo") |
||||
{ |
||||
foreach (XmlElement zq in elem.ChildNodes) |
||||
{ |
||||
if (zq.Name == "AppID") |
||||
{ |
||||
return zq.InnerText; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
return ""; |
||||
} |
||||
void FindSmartX1() |
||||
{ |
||||
try |
||||
{ |
||||
Rtn = smart.SmartX1Find(appid, keyHandles, keyNumber); |
||||
if (Rtn == 0) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
Rtn = smart.SmartX1Find(appid2, keyHandles, keyNumber); |
||||
if (Rtn == 0) |
||||
{ |
||||
return; |
||||
} |
||||
IsQuit = true; |
||||
t1 = DateTime.Now; |
||||
t2 = DateTime.Now; |
||||
t11 = DateTime.Now; |
||||
|
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
Debug.Log("异常" + ex.Message); |
||||
Application.Quit(); |
||||
} |
||||
} |
||||
void CheckExist() |
||||
{ |
||||
try |
||||
{ |
||||
Rtn = smart.SmartX1CheckExist(keyHandles[0]); |
||||
if (Rtn != 0) |
||||
{ |
||||
IsQuit = true; |
||||
} |
||||
|
||||
if (IsQuit) |
||||
{ |
||||
t1 = DateTime.Now; |
||||
t2 = DateTime.Now; |
||||
t11 = DateTime.Now; |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
Debug.Log("异常" + ex.Message); |
||||
Application.Quit(); |
||||
} |
||||
} |
||||
private GUIStyle tipStyle; |
||||
private int timer = 5; |
||||
void OnGUI() |
||||
{ |
||||
if (IsQuit) |
||||
{ |
||||
t2 = DateTime.Now; |
||||
if (t2 - t11 > new TimeSpan(0, 0, 1)) |
||||
{ |
||||
if (timer > 0) |
||||
timer--; |
||||
t11 = t2; |
||||
} |
||||
GUI.Label(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 75, 300, 150), "密钥验证失败,程序将在" + timer + "秒后退出!", tipStyle); |
||||
|
||||
if (t2 - t1 > new TimeSpan(0, 0, 5)) |
||||
{ |
||||
Debug.Log("程序退出!"); |
||||
Application.Quit(); |
||||
} |
||||
} |
||||
} |
||||
// Update is called once per frame |
||||
void Update() |
||||
{ |
||||
if (IsQuit) |
||||
return; |
||||
t2 = DateTime.Now; |
||||
if (t2 - t1 > new TimeSpan(0, 0, 0, 10, 0)) |
||||
{ |
||||
t1 = t2; |
||||
CheckExist(); |
||||
} |
||||
} |
||||
|
||||
|
||||
//xml文件加密解密 |
||||
|
||||
string ControlXML(string originalFile, string encodeFile, string decodeFile) |
||||
{ |
||||
var id = ""; |
||||
if (File.Exists(originalFile))//证明这次是第一次运行该程序,获取当前配置文件 |
||||
{ |
||||
id = GetAppID(originalFile); |
||||
fileEncryption(originalFile, encodeFile); |
||||
if (File.Exists(encodeFile)) |
||||
{ |
||||
File.Delete(originalFile); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
if (File.Exists(encodeFile)) |
||||
{ |
||||
fileDcryption(encodeFile, decodeFile); |
||||
if (File.Exists(decodeFile)) |
||||
{ |
||||
id = GetAppID(decodeFile); |
||||
File.Delete(decodeFile); |
||||
} |
||||
} |
||||
} |
||||
//Debug.Log("--------->" + id); |
||||
return id; |
||||
} |
||||
|
||||
//加密xml文件 |
||||
private void Encrypt(XmlDocument doc, string ElementName, SymmetricAlgorithm key) |
||||
{ |
||||
XmlElement elementEncrypt = doc.GetElementsByTagName(ElementName)[0] as XmlElement; |
||||
EncryptedXml eXml = new EncryptedXml(); |
||||
byte[] encryptElement = eXml.EncryptData(elementEncrypt, key, false);// |
||||
EncryptedData edElement = new EncryptedData(); |
||||
edElement.Type = EncryptedXml.XmlEncElementUrl; |
||||
string encryptionMethod = null; |
||||
|
||||
if (key is TripleDES) |
||||
{ |
||||
encryptionMethod = EncryptedXml.XmlEncTripleDESUrl; |
||||
} |
||||
else if (key is DES) |
||||
{ |
||||
encryptionMethod = EncryptedXml.XmlEncDESUrl; |
||||
} |
||||
|
||||
if (key is Rijndael) |
||||
{ |
||||
switch (key.KeySize) |
||||
{ |
||||
case 128: |
||||
encryptionMethod = EncryptedXml.XmlEncAES128Url; |
||||
break; |
||||
case 192: |
||||
encryptionMethod = EncryptedXml.XmlEncAES192Url; |
||||
break; |
||||
case 256: |
||||
encryptionMethod = EncryptedXml.XmlEncAES256Url; |
||||
break; |
||||
} |
||||
} |
||||
edElement.EncryptionMethod = new EncryptionMethod(encryptionMethod); |
||||
edElement.CipherData.CipherValue = encryptElement; |
||||
EncryptedXml.ReplaceElement(elementEncrypt, edElement, false); |
||||
} |
||||
|
||||
//XML文件解密 |
||||
private void Decrypt(XmlDocument doc, SymmetricAlgorithm Alg) |
||||
{ |
||||
XmlElement encryptedElement = doc.GetElementsByTagName("EncryptedData")[0] as XmlElement; |
||||
EncryptedData edElement = new EncryptedData(); |
||||
edElement.LoadXml(encryptedElement); |
||||
EncryptedXml exml = new EncryptedXml(); |
||||
byte[] rgbOutput = exml.DecryptData(edElement, Alg); |
||||
exml.ReplaceData(encryptedElement, rgbOutput); |
||||
} |
||||
|
||||
string original_filepath = ""; |
||||
string encode_filepath = ""; |
||||
string decode_filepath = ""; |
||||
|
||||
string original_filepath2 = ""; |
||||
string encode_filepath2 = ""; |
||||
string decode_filepath2 = ""; |
||||
//举例,对某个XML文件加密 |
||||
private void fileEncryption(string originalFile, string encodeFile) |
||||
{ |
||||
RijndaelManaged key = new RijndaelManaged(); |
||||
//设置密钥:key为32位=数字或字母16个=汉子8个 |
||||
byte[] byteKey = Encoding.Unicode.GetBytes("1111111111111111"); |
||||
key.Key = byteKey; |
||||
XmlDocument xmldoc = new XmlDocument(); |
||||
xmldoc.PreserveWhitespace = true; |
||||
xmldoc.Load(originalFile);//想要加密的xml文件 |
||||
Encrypt(xmldoc, "SmartX1", key);//需要加密的节点 |
||||
if (key != null) |
||||
{ |
||||
key.Clear(); |
||||
} |
||||
xmldoc.Save(encodeFile);//生成加密后的xml文件 |
||||
} |
||||
//举例,对某个xml文件解密 |
||||
private void fileDcryption(string encodeFile, string decodeFile) |
||||
{ |
||||
RijndaelManaged key = new RijndaelManaged(); |
||||
byte[] byteKey = Encoding.Unicode.GetBytes("1111111111111111"); |
||||
key.Key = byteKey; |
||||
XmlDocument xmldoc = new XmlDocument(); |
||||
xmldoc.PreserveWhitespace = true; |
||||
xmldoc.Load(encodeFile);//加载要解密的xml文件 |
||||
Decrypt(xmldoc, key); |
||||
if (key != null) |
||||
{ |
||||
key.Clear(); |
||||
} |
||||
xmldoc.Save(decodeFile);//生成解密后的文件 |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ae7ba88dc2eb0ac428673f57e7adae5e |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,214 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Runtime.InteropServices; |
||||
using System.Security.Cryptography; |
||||
|
||||
namespace SmartX1Demo |
||||
{ |
||||
public class SmartX1_X86 |
||||
{ |
||||
|
||||
//注意不要添加.dll后缀 |
||||
// Find |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Find(string appID, int[] keyHandles, int[] keyNumber); |
||||
|
||||
//open |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Open(int keyHandle, int uPin1, int uPin2, int uPin3, int uPin4); |
||||
//close |
||||
|
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Close(int keyHandle); |
||||
|
||||
//checkExist |
||||
|
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1CheckExist(int keyHandle); |
||||
|
||||
//getUid |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1GetUid(int keyHandle, StringBuilder uid); |
||||
|
||||
//ReadStorage |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1ReadStorage(int keyHandle, int startAddr, int length, byte[] pBuffer); |
||||
|
||||
//WriteStorage |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1WriteStorage(int keyHandle, int startAddr, int length, byte[] pBuffer); |
||||
|
||||
//PageLogin |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1PageLogin(int keyHandle, int pageNo, byte[] password, int length); |
||||
|
||||
//PageLogout |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1PageLogout(int keyHandle, int pageNo); |
||||
|
||||
//ReadPage |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1ReadPage(int keyHandle, int pageNo, int startAddr, ref int length, byte[] pBuffer); |
||||
|
||||
//WritePage |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1WritePage(int keyHandle, int pageNo, int startAddr, int length, byte[] pBuffer); |
||||
|
||||
//ReadMem |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1ReadMem(int keyHandle, int start, int length, byte[] pBuffer); |
||||
|
||||
//WriteMem |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1WriteMem(int keyHandle, int start, int length, byte[] pBuffer); |
||||
|
||||
//encrypt |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1TriDesEncrypt(int keyHandle, int buffSize, byte[] pBuffer); |
||||
|
||||
//desDecrypt |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1TriDesDecrypt(int keyHandle, int buffSize, byte[] pBuffer); |
||||
|
||||
//led |
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Led(int keyHandle, int state); |
||||
|
||||
|
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1PageGetProperty(int keyHandle, int pageNo, int propId, int[] propValue); |
||||
|
||||
[DllImport("SmartX1App", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1GetSoftVersion(int keyHandle, int[] version); |
||||
|
||||
public static string TridesEncrypt(string data, string key, Encoding encoding) |
||||
{ |
||||
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); |
||||
des.Key = Encoding.Default.GetBytes(key); |
||||
des.Mode = CipherMode.ECB; |
||||
|
||||
des.Padding = PaddingMode.PKCS7; |
||||
|
||||
ICryptoTransform DesEncrypt = des.CreateEncryptor(); |
||||
byte[] dataBytes = encoding.GetBytes(data); |
||||
byte[] outPut = DesEncrypt.TransformFinalBlock(dataBytes, 0, dataBytes.Length); |
||||
return Convert.ToBase64String(outPut); |
||||
|
||||
} |
||||
|
||||
public static string TridesDecEncrypt(byte[] data, string key, Encoding encoding) |
||||
{ |
||||
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); |
||||
des.Key = Encoding.Default.GetBytes(key); |
||||
des.Padding = PaddingMode.PKCS7; |
||||
des.Mode = CipherMode.ECB; |
||||
ICryptoTransform DesDecEncrypt = des.CreateDecryptor(); |
||||
byte[] outValue = DesDecEncrypt.TransformFinalBlock(data, 0, data.Length); |
||||
return encoding.GetString(outValue); |
||||
} |
||||
} |
||||
|
||||
|
||||
class SmartX1_X64 |
||||
{ |
||||
// Find |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Find(string appID, int[] keyHandles, int[] keyNumber); |
||||
|
||||
//open |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Open(int keyHandle, int uPin1, int uPin2, int uPin3, int uPin4); |
||||
//close |
||||
|
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Close(int keyHandle); |
||||
|
||||
//checkExist |
||||
|
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1CheckExist(int keyHandle); |
||||
|
||||
//getUid |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1GetUid(int keyHandle, StringBuilder uid); |
||||
|
||||
//ReadStorage |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1ReadStorage(int keyHandle, int startAddr, int length, byte[] pBuffer); |
||||
|
||||
//WriteStorage |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1WriteStorage(int keyHandle, int startAddr, int length, byte[] pBuffer); |
||||
|
||||
//PageLogin |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1PageLogin(int keyHandle, int pageNo, byte[] password, int length); |
||||
|
||||
//PageLogout |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1PageLogout(int keyHandle, int pageNo); |
||||
|
||||
//ReadPage |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1ReadPage(int keyHandle, int pageNo, int startAddr, ref int length, byte[] pBuffer); |
||||
|
||||
//WritePage |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1WritePage(int keyHandle, int pageNo, int startAddr, int length, byte[] pBuffer); |
||||
|
||||
//ReadMem |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1ReadMem(int keyHandle, int start, int length, byte[] pBuffer); |
||||
|
||||
//WriteMem |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1WriteMem(int keyHandle, int start, int length, byte[] pBuffer); |
||||
|
||||
//encrypt |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1TriDesEncrypt(int keyHandle, int buffSize, byte[] pBuffer); |
||||
|
||||
//desDecrypt |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1TriDesDecrypt(int keyHandle, int buffSize, byte[] pBuffer); |
||||
|
||||
//led |
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1Led(int keyHandle, int state); |
||||
|
||||
|
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1PageGetProperty(int keyHandle, int pageNo, int propId, int[] propValue); |
||||
|
||||
[DllImport("SmartX1AppX64", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] |
||||
public static extern int SmartX1GetSoftVersion(int keyHandle, int[] version); |
||||
|
||||
public static string TridesEncrypt(string data, string key, Encoding encoding) |
||||
{ |
||||
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); |
||||
des.Key = Encoding.Default.GetBytes(key); |
||||
des.Mode = CipherMode.ECB; |
||||
|
||||
des.Padding = PaddingMode.PKCS7; |
||||
|
||||
ICryptoTransform DesEncrypt = des.CreateEncryptor(); |
||||
byte[] dataBytes = encoding.GetBytes(data); |
||||
byte[] outPut = DesEncrypt.TransformFinalBlock(dataBytes, 0, dataBytes.Length); |
||||
return Convert.ToBase64String(outPut); |
||||
|
||||
} |
||||
|
||||
public static string TridesDecEncrypt(byte[] data, string key, Encoding encoding) |
||||
{ |
||||
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); |
||||
des.Key = Encoding.Default.GetBytes(key); |
||||
des.Padding = PaddingMode.PKCS7; |
||||
des.Mode = CipherMode.ECB; |
||||
ICryptoTransform DesDecEncrypt = des.CreateDecryptor(); |
||||
byte[] outValue = DesDecEncrypt.TransformFinalBlock(data, 0, data.Length); |
||||
return encoding.GetString(outValue); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 29d71005b2314cb49b256b33cfcd8fbd |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ff439bf6b06edd64eaec52f14d1c6da6 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue