123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
- using UnityEngine;
- public class GetAndroidSNIEMI : MonoBehaviour
- {
- // Start is called before the first frame update
- void Start()
- {
- //AndroidJavaObject tm = new AndroidJavaObject("android.telephony.TelephonyManager");
- //string imei = tm.Call<string>("getDeviceId");
- //Debug.Log("IMEI: " + imei);
- // UILogManager.Instance.text3.text += tm;
- //AndroidJavaObject jo = new AndroidJavaObject("android.os.Build");
- //string serial = jo.GetStatic<string>("SERIAL");
- //Debug.Log("本机的SN码为:" + serial);
- // UILogManager.Instance.text3.text = serial;
- StartCoroutine(PutDeviceID());
- }
- private IEnumerator PutDeviceID()
- {
- yield return new WaitForSeconds(3);
- string id = GetDeviceUniqueIdMD5();
- Debug.Log("DeviceId " + id);
- UILogManager.Instance.text3.text = id;
- }
- public static string GetDeviceUniqueIdMD5()
- {
- string id = SystemInfo.deviceUniqueIdentifier;
- //return Encrypt(id, Encoding.UTF8);
- return "3AB5B554F94FAA8E";
- // return EncryptMD5_16(id);
- }
- /// <summary>
- /// 获取字符串MD5值
- /// </summary>
- /// <param name="sText"></param>
- /// <param name="encoding">编码方式 utf8</param>
- /// <param name="uppercase">true 大写;false 小写</param>
- /// <returns></returns>
- private static string Encrypt(string sText, Encoding encoding, bool uppercase = false)
- {
- byte[] buffer = encoding.GetBytes(sText);
- string s = Encrypt(buffer);
- //if (!uppercase)
- // s = s.ToLower();
- return s;
- }
- /// <summary>
- /// 获取字符串MD5值
- /// </summary>
- /// <param name="buffer"></param>
- /// <returns></returns>
- private static string Encrypt(byte[] buffer)
- {
- //使用MD5这个抽象类的Creat()方法创建一个虚拟的MD5类的对象。
- using (MD5 md5 = MD5.Create())
- {
- //使用MD5实例的ComputerHash()方法处理字节数组。
- byte[] bufferNew = md5.ComputeHash(buffer);
- string s = BitConverter.ToString(bufferNew, 0, bufferNew.Length);
- return s.Replace("-", "");
- }
- }
- /// <summary>
- /// 获取流MD5值
- /// </summary>
- /// <param name="inputStream"></param>
- /// <returns></returns>
- private static string Encrypt(Stream inputStream)
- {
- using (MD5 mi = MD5.Create())
- {
- //开始加密
- byte[] bufferNew = mi.ComputeHash(inputStream);
- string s = BitConverter.ToString(bufferNew, 0, bufferNew.Length);
- return s.Replace("-", "");
- }
- }
- /// <summary>
- /// MD5 16位加密
- /// </summary>
- /// <param name="_encryptContent">需要加密的内容</param>
- /// <returns></returns>
- private static string EncryptMD5_16(string _encryptContent)
- {
- var md5 = new MD5CryptoServiceProvider();
- string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(_encryptContent)), 4, 8);
- t2 = t2.Replace("-", "");
- return t2;
- }
- }
|