Beispiel #1
0
        public static string GetSHA1(Android.Content.Context ctx)
        {
            string result = string.Empty;

            try
            {
                var info      = ctx.PackageManager.GetPackageInfo(ctx.PackageName, Android.Content.PM.PackageInfoFlags.Signatures);
                var cert      = info.Signatures[0].ToByteArray();
                var md        = MessageDigest.GetInstance("SHA1");
                var publicKey = md.Digest(cert);
                Java.Lang.StringBuffer hexString = new Java.Lang.StringBuffer();
                for (int i = 0; i < publicKey.Length; i++)
                {
                    string appendString = new Java.Lang.String(String.Format("{0:X}", (0xFF & publicKey[i]))).ToUpperCase(Java.Util.Locale.Us);

                    if (appendString.Length == 1)
                    {
                        hexString.Append("0");
                    }

                    hexString.Append(appendString);
                    hexString.Append(":");
                }

                result = hexString.ToString();
                result = result.Substring(0, result.Length - 1);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(result);
        }
Beispiel #2
0
 public string ReadAuthFile(string FileName = "Auth.ini")
 {
     try
     {
         Java.Lang.StringBuffer sb = new Java.Lang.StringBuffer();
         //文件不存在
         if (!System.IO.File.Exists(FileName))
         {
             return(string.Empty);
         }
         System.IO.Stream fis = context.OpenFileInput(FileName);
         int ch;
         while ((ch = fis.ReadByte()) != -1)
         {
             sb.Append((char)ch);
         }
         fis.Close();
         string AuthMsg = sb.ToString();
         Logger.Debug("AuthMsg:" + AuthMsg);
         if (string.IsNullOrEmpty(AuthMsg))
         {
             AuthMsg = ReadDecryptorFile(AuthFileName);
             Logger.Debug("ReadDecryptorFile:" + AuthMsg);
         }
         return(AuthMsg);
     }
     catch (Exception exp)
     {
         //记录详细日志
         Logger.Error(exp, GetType().ToString());
         return(string.Empty);
     }
 }
	    private static String BytesToHexString(byte[] bytes) {
	        // http://stackoverflow.com/questions/332079
	        Java.Lang.StringBuffer sb = new Java.Lang.StringBuffer();
	        for (int i = 0; i < bytes.Length; i++) {
	            String hex = Java.Lang.Integer.ToHexString(0xFF & bytes[i]);
	            if (hex.Length == 1) {
	                sb.Append('0');
	            }
	            sb.Append(hex);
	        }
	        return sb.ToString();
	    }
Beispiel #4
0
        /// <summary>
        /// Append string content to the given buffer.
        /// </summary>
        internal override void AppendTextTo(Java.Lang.StringBuffer buffer)
        {
            var text = content as string;

            if (text != null)
            {
                buffer.Append(text);
            }
            else if (content is XNode)
            {
                foreach (var node in Nodes())
                {
                    node.AppendTextTo(buffer);
                }
            }
        }
Beispiel #5
0
        public string ReadAuthFile(Context context)
        {
            try
            {
                Java.Lang.StringBuffer sb  = new Java.Lang.StringBuffer();
                System.IO.Stream       fis = context.OpenFileInput("Auth.ini");

                int ch;
                while ((ch = fis.ReadByte()) != -1)
                {
                    sb.Append((char)ch);
                }
                fis.Close();
                string AuthMsg = sb.ToString();
                return(AuthMsg);
            }
            catch (Exception ex)
            {
            }
            return(string.Empty);
        }
		public static string GetMD5 (Java.Lang.String s)
		{
			try {
				// Create MD5 Hash
				var digest = Java.Security.MessageDigest.GetInstance ("MD5");
				digest.Update (s.GetBytes ());
				var messageDigest = digest.Digest ();

				// Create Hex String
				var hexString = new Java.Lang.StringBuffer ();
				for (int i = 0; i < messageDigest.Length; i++) {
					var h = Java.Lang.Integer.ToHexString (0xFF & messageDigest [i]);
					while (h.Length < 2) {
						h = "0" + h;
					}
					hexString.Append (h);
				}
				return hexString.ToString ();

			} catch (Java.Security.NoSuchAlgorithmException ex) {
				Log.Debug (TAG, ex.StackTrace);
			}
			return "";
		}
Beispiel #7
0
 public static Java.Lang.StringBuffer append(this Java.Lang.StringBuffer buffer, char value)
 {
     buffer.Append(value);
     return(buffer);
 }
Beispiel #8
0
 public static Java.Lang.StringBuffer append(this Java.Lang.StringBuffer buffer, string str)
 {
     buffer.Append(str);
     return(buffer);
 }
Beispiel #9
0
 public static Java.Lang.StringBuffer append(this Java.Lang.StringBuffer buffer, Java.Lang.ICharSequence value)
 {
     buffer.Append(value);
     return(buffer);
 }
Beispiel #10
0
 /// <summary>
 /// Append string content to the given buffer.
 /// </summary>
 internal virtual void AppendTextTo(Java.Lang.StringBuffer buffer)
 {
     // Override me
 }
Beispiel #11
0
 /// <summary>
 /// Append string content to the given buffer.
 /// </summary>
 internal override void AppendTextTo(Java.Lang.StringBuffer buffer)
 {
     buffer.Append(value);
 }