title: Key hash for Android-Facebook app in Kotlin Programmatically
body: <p>I'm trying to get the hash key in kotlin for facebook-app before that i use this java method to get hask key for my apps: </p>
  
  <p><strong>Java code:</strong></p>
  
  <pre><code>// Add code to print out the key hash
      try {
          PackageInfo info = getPackageManager().getPackageInfo(
                  "your.package", 
                  PackageManager.GET_SIGNATURES);
          for (Signature signature : info.signatures) {
              MessageDigest md = MessageDigest.getInstance("SHA");
              md.update(signature.toByteArray());
              Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
              }
      } catch (NameNotFoundException e) {
  
      } catch (NoSuchAlgorithmException e) {
  
      }
  </code></pre>
  
  <p>Now i tried this code snippet by converting it into kotlin code: </p>
  
  <p><strong>Kotlin Code:</strong></p>
  
  <pre><code>    try {
             val info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
              for (signature in info.signatures) {
                  val md = MessageDigest.getInstance("SHA")
                  md.update(signature.toByteArray())
                  Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT))
              }
      } catch (e: PackageManager.NameNotFoundException) {
                      e.printStackTrace()
      } catch (e: NoSuchAlgorithmException) {
                      e.printStackTrace()
      }
  </code></pre>
  
  <p>but getting error on this line of code i have tried some solutions but didn't get anything useful:  </p>
  
  <pre><code>      Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT))
  </code></pre>
  
  <p><code>encodeToString</code> is unresolved and same for <code>Base64.DEFAULT</code>.</p>
  
  <p>Thanks in advance for your time.</p>