Ejemplo n.º 1
0
        /// <summary>A helper class to sha1 hash all the strings in a collection</summary>
        /// <param name="nquads"></param>
        /// <returns></returns>
        private static string Sha1hash(ICollection <string> nquads)
        {
#if !PORTABLE
            try
            {
                // create SHA-1 digest
                MessageDigest md = MessageDigest.GetInstance("SHA-1");
                foreach (string nquad in nquads)
                {
                    md.Update(JsonLD.JavaCompat.GetBytesForString(nquad, "UTF-8"));
                }
                return(EncodeHex(md.Digest()));
            }
            //catch (NoSuchAlgorithmException e)
            //{
            //    throw new Exception(e);
            //}
            catch
            {
                throw;
            }
#else
            throw new PlatformNotSupportedException();
#endif
        }
        private string GetCurrentSignatureForPackage(string packageName)
        {
            try
            {
                PackageInfo info = Application.Context.PackageManager.GetPackageInfo(packageName,
                                                                                     PackageInfoFlags.Signatures);
#pragma warning disable CS0618 // Type or member is obsolete - https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/1854
                if (info != null && info.Signatures != null && info.Signatures.Count > 0)
                {
                    Signature     signature = info.Signatures[0];
                    MessageDigest md        = MessageDigest.GetInstance("SHA");
                    md.Update(signature.ToByteArray());
                    return(Convert.ToBase64String(md.Digest(), Base64FormattingOptions.None));
                    // Server side needs to register all other tags. ADAL will
                    // send one of them.
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
            catch (PackageManager.NameNotFoundException)
            {
                _logger.Info("Calling App's package does not exist in PackageManager");
            }
            catch (NoSuchAlgorithmException)
            {
                _logger.Info("Digest SHA algorithm does not exists");
            }

            return(null);
        }
 /** Return the MD5 hash of a string. */
 private String md5(String str)
 {
     // Old devices have a bug where OpenSSL can leave MessageDigest in a bad state, but trying
     // multiple times seems to clear it.
     for (int i = 0; i < 3 /** max attempts */; ++i)
     {
         try
         {
             MessageDigest _md5 = MessageDigest.GetInstance("MD5");
             _md5.Update(Encoding.ASCII.GetBytes(str));
             return(new BigInteger(1, _md5.Digest()).ToString(16)
                    .ToUpper().PadLeft(32, '0'));
         }
         catch (NoSuchAlgorithmException e)
         {
             // Try again.
             Log.Error(TAG, e.Message);
         }
         catch (ArithmeticException ex)
         {
             Log.Error(TAG, ex.Message);
             return(null);
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            FacebookSdk.SdkInitialize(this);
            CarouselViewRenderer.Init();
            CrossCurrentActivity.Current.Init(this, bundle);
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());

            //NEDS for get correct debug keyhash

            PackageInfo info = this.PackageManager.GetPackageInfo("com.impressolabs.Impresso", PackageInfoFlags.Signatures);

            foreach (Android.Content.PM.Signature signature in info.Signatures)
            {
                MessageDigest md = MessageDigest.GetInstance("SHA");
                md.Update(signature.ToByteArray());

                string keyhash = Convert.ToBase64String(md.Digest());
                Console.WriteLine("KeyHash:", keyhash);
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public FileHandle(string s)
        {
            MessageDigest digest;

            try
            {
                digest = MessageDigest.GetInstance("MD5");
                handle = new byte[HandleLen];
            }
            catch (NoSuchAlgorithmException)
            {
                Log.Warn("MD5 MessageDigest unavailable.");
                handle = null;
                return;
            }
            byte[] @in = Runtime.GetBytesForString(s, Charsets.Utf8);
            digest.Update(@in);
            byte[] digestbytes = digest.Digest();
            for (int i = 0; i < 16; i++)
            {
                handle[i] = unchecked ((byte)0);
            }
            for (int i_1 = 16; i_1 < 32; i_1++)
            {
                handle[i_1] = digestbytes[i_1 - 16];
            }
        }
Ejemplo n.º 7
0
        public static BlobKey KeyForBlobFromFile(FilePath file)
        {
            MessageDigest md;

            try
            {
                md = MessageDigest.GetInstance("SHA-1");
            }
            catch (NoSuchAlgorithmException)
            {
                Log.E(Log.TagBlobStore, "Error, SHA-1 digest is unavailable.");
                return(null);
            }
            byte[] sha1hash = new byte[40];
            try
            {
                FileInputStream fis     = new FileInputStream(file);
                byte[]          buffer  = new byte[65536];
                int             lenRead = fis.Read(buffer);
                while (lenRead > 0)
                {
                    md.Update(buffer, 0, lenRead);
                    lenRead = fis.Read(buffer);
                }
                fis.Close();
            }
            catch (IOException)
            {
                Log.E(Log.TagBlobStore, "Error readin tmp file to compute key");
            }
            sha1hash = md.Digest();
            BlobKey result = new BlobKey(sha1hash);

            return(result);
        }
Ejemplo n.º 8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            uiHelper = new UiLifecycleHelper(this, callback);
            uiHelper.OnCreate(savedInstanceState);


            var info = PackageManager.GetPackageInfo("com.sammdesmond.popPIC", Android.Content.PM.PackageInfoFlags.Signatures);

            foreach (var signature in info.Signatures)
            {
                MessageDigest me = MessageDigest.GetInstance("SHA");
                me.Update(signature.ToByteArray());
                var s = Base64.EncodeToString(me.Digest(), Base64Flags.Default);
                Log.Error("ssl key", s);
                // ShowAlert ("Danny ignore this", s);
            }

            SetContentView(Resource.Layout.loginPage);

            loginButton = (LoginButton)FindViewById(Resource.Id.login_button);
            loginButton.UserInfoChangedCallback = new MyUserInfoChangedCallback(this);
            loginButton.LoginBehavior           = SessionLoginBehavior.SsoWithFallback;
            greeting = FindViewById <TextView> (Resource.Id.greeting);

            var activeSession = Session.OpenActiveSessionFromCache(this);

            if (activeSession != null && activeSession.IsOpened)
            {
                // Do somethign interesting!
            }
        }
Ejemplo n.º 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                PackageInfo info = Android.App.Application.Context.PackageManager.GetPackageInfo(Android.App.Application.Context.PackageName, PackageInfoFlags.Signatures);
                foreach (var signature in info.Signatures)
                {
                    MessageDigest md = MessageDigest.GetInstance("SHA");
                    md.Update(signature.ToByteArray());

                    System.Diagnostics.Debug.WriteLine(Convert.ToBase64String(md.Digest()));
                }
            }
            catch (NoSuchAlgorithmException e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }



            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
Ejemplo n.º 10
0
        private static String Hash(string packageName, string signature)
        {
            string appInfo = packageName + " " + signature;

            try
            {
                MessageDigest messageDigest = MessageDigest.GetInstance(HASH_TYPE);
                byte[]        input         = Encoding.UTF8.GetBytes(appInfo);
                messageDigest.Update(input);
                byte[] hashSignature = messageDigest.Digest();

                // truncated into NUM_HASHED_BYTES
                //hashSignature = Arrays.copyOfRange(hashSignature, 0, NUM_HASHED_BYTES);
                Array.Copy(hashSignature, hashSignature, NUM_HASHED_BYTES);

                // encode into Base64
                string base64Hash = Base64.EncodeToString(hashSignature, Base64Flags.NoPadding | Base64Flags.NoWrap);
                base64Hash = base64Hash.Substring(0, NUM_BASE64_CHAR);

                Log.Debug(TAG, string.Format("pkg: %s -- hash: %s", packageName, base64Hash));
                return(base64Hash);
            }
            catch (NoSuchAlgorithmException exp)
            {
                Log.Error(TAG, "hash:NoSuchAlgorithm", exp);
            }
            catch (System.Exception exp)
            {
                Log.Error(TAG, "hash:Exception", exp);
            }
            return(null);
        }
Ejemplo n.º 11
0
        public string hashCal(string type, string str)
        {
            StringBuffer hexString = new StringBuffer();

            try
            {
                MessageDigest digestTxID = null;
                digestTxID = MessageDigest.GetInstance(type);
                digestTxID.Reset();
                digestTxID.Update(Encoding.ASCII.GetBytes(str.ToString()));
                byte[] messageDigest = digestTxID.Digest();

                for (int i = 0; i < messageDigest.Length; i++)
                {
                    string hex = Integer.ToHexString(0xFF & messageDigest[i]);
                    if (hex.Length == 1)
                    {
                        hexString.Append("0");
                    }
                    hexString.Append(hex);
                }
            }
            catch (NoSuchAlgorithmException nsae) { }

            return(hexString.ToString());
        }
Ejemplo n.º 12
0
        public Certificate(string host, SslCertificate certificate)
        {
            _host = host;

            // A really circuitous path to getting the public key data.
            var bundle          = SslCertificate.SaveState(certificate);
            var bytes           = bundle.GetByteArray("x509-certificate");
            var factory         = CertificateFactory.GetInstance("X.509");
            var x509Certificate = factory.GenerateCertificate(new MemoryStream(bytes));
            var messageDigest   = MessageDigest.GetInstance("SHA-1");

            messageDigest.Update(x509Certificate.GetEncoded());
            _hashBytes = messageDigest.Digest();

            var encodedBytes = x509Certificate.PublicKey.GetEncoded();

            // The encoded public key uses the ASN.1 encoded SubjectPublicKeyInfo structure.
            // The .Net X509Certificate class, which we use on iOS, gives us a subset of that
            // data (sans the header). Therefore we strip off the header to get the same data
            // on both platforms.

            var publicKeyLength = encodedBytes.Length - SubjectPublicKeyInfoHeaderLength;
            var publicKeyBytes  = new byte[publicKeyLength];

            Array.Copy(encodedBytes, SubjectPublicKeyInfoHeaderLength, publicKeyBytes, 0, publicKeyLength);

            _publicKeyBytes = publicKeyBytes;

            _hashString      = new Lazy <string>(() => ByteArrayToHexString(_hashBytes));
            _publicKeyString = new Lazy <string>(() => ByteArrayToHexString(_publicKeyBytes));
        }
Ejemplo n.º 13
0
        public static BlobKey KeyForBlobFromFile(FileInfo file)
        {
            MessageDigest md;

            try {
                md = MessageDigest.GetInstance("SHA-1");
            } catch (NoSuchAlgorithmException) {
                Log.E(Database.TAG, "Error, SHA-1 digest is unavailable.");
                return(null);
            }

            byte[] sha1hash = new byte[40];
            try {
                var    fis     = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                byte[] buffer  = new byte[65536];
                int    lenRead = fis.Read(buffer, 0, buffer.Length);
                while (lenRead > 0)
                {
                    md.Update(buffer, 0, lenRead);
                    lenRead = fis.Read(buffer, 0, buffer.Length);
                }
                fis.Close();
            } catch (IOException) {
                Log.E(Database.TAG, "Error readin tmp file to compute key");
            }

            sha1hash = md.Digest();
            BlobKey result = new BlobKey(sha1hash);

            return(result);
        }
Ejemplo n.º 14
0
        public static string md5(string str)
        {
            MessageDigest md5 = null;

            try
            {
                md5 = MessageDigest.GetInstance("MD5");
                byte[] bytes  = md5.Digest(System.Text.Encoding.Default.GetBytes(str));
                string result = "";
                foreach (byte b in bytes)
                {
                    string temp = Java.Lang.Integer.ToHexString(b & 0xff);
                    if (temp.Length == 1)
                    {
                        temp = "0" + temp;
                    }
                    result += temp;
                }
                return(result);
            }
            catch (NoSuchAlgorithmException e)
            {
            }
            return("");
        }
Ejemplo n.º 15
0
        private string GetCurrentSignatureForPackage(string packageName)
        {
            try
            {
                PackageInfo info = Application.Context.PackageManager.GetPackageInfo(packageName,
                                                                                     PackageInfoFlags.Signatures);
                if (info != null && info.Signatures != null && info.Signatures.Count > 0)
                {
                    Signature     signature = info.Signatures[0];
                    MessageDigest md        = MessageDigest.GetInstance("SHA");
                    md.Update(signature.ToByteArray());
                    return(Convert.ToBase64String(md.Digest(), Base64FormattingOptions.None));
                    // Server side needs to register all other tags. ADAL will
                    // send one of them.
                }
            }
            catch (PackageManager.NameNotFoundException)
            {
                _logger.Info("Calling App's package does not exist in PackageManager");
            }
            catch (NoSuchAlgorithmException)
            {
                _logger.Info("Digest SHA algorithm does not exists");
            }

            return(null);
        }
Ejemplo n.º 16
0
        private int CreateSsrc(string hostName)
        {
            try
            {
                ObjectIDGenerator obGen = new ObjectIDGenerator();

                MessageDigest md = MessageDigest.GetInstance("MD5");
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Convert.ToString(new Date().Time).ToCharArray()));
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Convert.ToString(obGen.ToString().ToCharArray())));
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Paths.Get("").ToAbsolutePath().Normalize().ToString().ToCharArray()));
                md.Update(Encoding.GetEncoding("UTF-8").GetBytes(hostName.ToCharArray()));
                byte[]     md5        = md.Digest();
                int        ssrc       = 0;
                ByteBuffer byteBuffer = ByteBuffer.Wrap(md5);
                for (int i = 0; i < 3; i++)
                {
                    ssrc ^= byteBuffer.Int;
                }
                return(ssrc);
            }
            catch (NoSuchAlgorithmException e)
            {
                throw new RuntimeException("Could not get MD5 algorithm", e);
            }
        }
Ejemplo n.º 17
0
        /**
         * Helps identify the source file
         */
        private static String GetFileMD5(File f)
        {
            MessageDigest m;

            try
            {
                m = MessageDigest.GetInstance("MD5");
            }
            catch (NoSuchAlgorithmException e)
            {
                throw new RuntimeException(e);
            }

            byte[] buf = new byte[2048];
            try
            {
                InputStream is1 = new FileInputStream(f);
                while (true)
                {
                    int bytesRead = is1.Read(buf);
                    if (bytesRead < 1)
                    {
                        break;
                    }
                    m.update(buf, 0, bytesRead);
                }
                is1.Close();
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }

            return("0x" + new Bigint(1, m.digest()).ToString(16));
        }
Ejemplo n.º 18
0
 public static byte[] GetNtlm2Response(byte[] nTowFv1, byte[] serverChallenge, byte
                                       [] clientChallenge)
 {
     byte[] sessionHash = new byte[8];
     try
     {
         MessageDigest md5;
         md5 = MessageDigest.GetInstance("MD5");
         md5.Update(serverChallenge);
         md5.Update(clientChallenge, 0, 8);
         Array.Copy(md5.Digest(), 0, sessionHash, 0, 8);
     }
     catch (Exception gse)
     {
         if (_log.Level > 0)
         {
             Runtime.PrintStackTrace(gse, _log);
         }
         throw new RuntimeException("MD5", gse);
     }
     byte[] key = new byte[21];
     Array.Copy(nTowFv1, 0, key, 0, 16);
     byte[] ntResponse = new byte[24];
     E(key, sessionHash, ntResponse);
     return(ntResponse);
 }
        public static string Calculate(IDictionary <string, string> components, Func <string, MessageDigest, bool> passwordDigestBlock)
        {
            MessageDigest ha1md5      = MessageDigest.GetInstance("md5");
            MessageDigest ha2md5      = MessageDigest.GetInstance("md5");
            MessageDigest responsemd5 = MessageDigest.GetInstance("md5");

            var ha1Str = String.Format("{0}:{1}:", components.Get("username"), components.Get("realm"));

            ha1md5.Update(Encoding.UTF8.GetBytes(ha1Str));
            if (!passwordDigestBlock(components.Get("username"), ha1md5))
            {
                Log.To.Listener.W(TAG, "No password entered from passwordDigestBlock");
                return(null);
            }

            var ha1    = BitConverter.ToString(ha1md5.Digest()).Replace("-", "").ToLowerInvariant();
            var ha2Str = String.Format("{0}:{1}", components.Get("method"), components.Get("uri"));

            ha2md5.Update(Encoding.UTF8.GetBytes(ha2Str));
            var ha2 = BitConverter.ToString(ha2md5.Digest()).Replace("-", "").ToLowerInvariant();

            var responseStr = String.Format("{0}:{1}:{2}:{3}:{4}:{5}", ha1, components.Get("nonce"), components.Get("nc"),
                                            components.Get("cnonce"), components.Get("qop"), ha2);

            responsemd5.Update(Encoding.UTF8.GetBytes(responseStr));
            return(BitConverter.ToString(responsemd5.Digest()).Replace("-", "").ToLowerInvariant());
        }
Ejemplo n.º 20
0
        public static BlobKey KeyForBlobFromFile(string file)
        {
            MessageDigest md;

            try {
                md = MessageDigest.GetInstance("SHA-1");
            } catch (NotSupportedException) {
                Log.To.Database.E(TAG, "Error, SHA-1 digest is unavailable.");
                return(null);
            }

            byte[] sha1hash = new byte[40];
            try {
                using (var fis = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                    byte[] buffer  = new byte[65536];
                    int    lenRead = fis.Read(buffer, 0, buffer.Length);
                    while (lenRead > 0)
                    {
                        md.Update(buffer, 0, lenRead);
                        lenRead = fis.Read(buffer, 0, buffer.Length);
                    }
                }
            } catch (IOException e) {
                Log.To.Database.E(TAG, "Error reading tmp file to compute key (returning null)", e);
                return(null);
            }

            sha1hash = md.Digest();
            BlobKey result = new BlobKey(sha1hash);

            return(result);
        }
Ejemplo n.º 21
0
        /// <exception cref="SharpCifs.Smb.SmbException"></exception>
        public SigningDigest(SmbTransport transport, NtlmPasswordAuthentication auth)
        {
            try
            {
                _digest = MessageDigest.GetInstance("MD5");
            }
            catch (NoSuchAlgorithmException ex)
            {
                if (Log.Level > 0)
                {
                    Runtime.PrintStackTrace(ex, Log);
                }
                throw new SmbException("MD5", ex);
            }
            try
            {
                switch (SmbConstants.LmCompatibility)
                {
                case 0:
                case 1:
                case 2:
                {
                    _macSigningKey = new byte[40];
                    auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
                    Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
                               , 16, 24);
                    break;
                }

                case 3:
                case 4:
                case 5:
                {
                    _macSigningKey = new byte[16];
                    auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
                    break;
                }

                default:
                {
                    _macSigningKey = new byte[40];
                    auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
                    Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
                               , 16, 24);
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                throw new SmbException(string.Empty, ex);
            }
            if (Log.Level >= 5)
            {
                Log.WriteLine("LM_COMPATIBILITY=" + SmbConstants.LmCompatibility);
                Hexdump.ToHexdump(Log, _macSigningKey, 0, _macSigningKey.Length);
            }
        }
Ejemplo n.º 22
0
        /// <exception cref="System.Exception"/>
        public static MD5Hash GetTestHash()
        {
            MessageDigest digest = MessageDigest.GetInstance("MD5");

            byte[] buffer = new byte[1024];
            Random.NextBytes(buffer);
            digest.Update(buffer);
            return(new MD5Hash(digest.Digest()));
        }
Ejemplo n.º 23
0
 /// <exception cref="System.Exception"></exception>
 public virtual void Init()
 {
     try
     {
         md = MessageDigest.GetInstance("SHA-1");
     }
     catch (Exception e)
     {
         System.Console.Error.WriteLine(e);
     }
 }
Ejemplo n.º 24
0
 static MD5Filter()
 {
     try
     {
         Digester = MessageDigest.GetInstance("MD5");
     }
     catch (NoSuchAlgorithmException e)
     {
         throw new RuntimeException(e);
     }
 }
Ejemplo n.º 25
0
        /** Needed for the Digest Access Authentication. */
        private System.String computeMd5Hash(Java.Lang.String buffer)
        {
            MessageDigest md;

            try {
                md = MessageDigest.GetInstance("MD5");
                return(bytesToHex(md.Digest(buffer.GetBytes("UTF-8"))));
            } catch (NoSuchAlgorithmException ignore) {
            } catch (UnsupportedEncodingException e) {}
            return("");
        }
        private string GetThumbprintSha256(X509Certificate certificate)
        {
            var messageDigest = MessageDigest.GetInstance("SHA-256");
            var bytes         = certificate.GetEncoded();

            messageDigest.Update(bytes);

            var digest = messageDigest.Digest();

            return(digest.Aggregate(String.Empty, (str, hashByte) => str + hashByte.ToString("x2")));
        }
Ejemplo n.º 27
0
 private static MessageDigest NewMD5()
 {
     try
     {
         return(MessageDigest.GetInstance("MD5"));
     }
     catch (NoSuchAlgorithmException e)
     {
         throw new RuntimeException(JGitText.Get().JRELacksMD5Implementation, e);
     }
 }
Ejemplo n.º 28
0
 private static MessageDigest NewMD5()
 {
     try
     {
         return(MessageDigest.GetInstance("MD5"));
     }
     catch (NoSuchAlgorithmException e)
     {
         throw new RuntimeException("No MD5 available", e);
     }
 }
Ejemplo n.º 29
0
 /// <summary>Create a new digest function for objects.</summary>
 /// <remarks>Create a new digest function for objects.</remarks>
 /// <returns>a new digest object.</returns>
 /// <exception cref="Sharpen.RuntimeException">
 /// this Java virtual machine does not support the required hash
 /// function. Very unlikely given that JGit uses a hash function
 /// that is in the Java reference specification.
 /// </exception>
 public static MessageDigest NewMessageDigest()
 {
     try
     {
         return(MessageDigest.GetInstance(HASH_FUNCTION));
     }
     catch (NoSuchAlgorithmException nsae)
     {
         throw new RuntimeException(MessageFormat.Format(JGitText.Get().requiredHashFunctionNotAvailable
                                                         , HASH_FUNCTION), nsae);
     }
 }
Ejemplo n.º 30
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var density = Resources.DisplayMetrics.Density;

            App.screenWidth  = Resources.DisplayMetrics.WidthPixels / density;
            App.screenHeight = Resources.DisplayMetrics.HeightPixels / density;

            if (Xamarin.Forms.Device.Idiom == TargetIdiom.Phone)
            {
                App.screenHeight = (16 * App.screenWidth) / 9;
            }

            if (Xamarin.Forms.Device.Idiom == TargetIdiom.Tablet)
            {
                App.screenWidth = (9 * App.screenHeight) / 16;
            }

            try
            {
                PackageInfo info = Android.App.Application.Context.PackageManager.GetPackageInfo(Android.App.Application.Context.PackageName, PackageInfoFlags.Signatures);
                foreach (var signature in info.Signatures)
                {
                    MessageDigest md = MessageDigest.GetInstance("SHA");
                    md.Update(signature.ToByteArray());
                    System.Diagnostics.Debug.WriteLine("helloWorld");
                    System.Diagnostics.Debug.WriteLine(Convert.ToBase64String(md.Digest()));
                }
            }
            catch (NoSuchAlgorithmException e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }

            PrintHashKey(this);

            FacebookSdk.ApplicationId = "244197793511500";
            FacebookSdk.SdkInitialize(this);
            FacebookClientManager.Initialize(this);
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;
            FirebaseApp.InitializeApp(this);
            base.OnCreate(savedInstanceState);

            GoogleClientManager.Initialize(this);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }