[Kotlin] KakaoLogin KeyHash 발급

2021. 8. 27. 09:32
728x90

 [ 방법#1 ] 

getKeyHash() 메서드로 구현

private fun kakaoLoginStart(){
	Log.d(TAG, "LoginActivity - kakaoLoginStart() called")
      
	// keyHash 발급
	getKeyHash(this)

	// Kakao Login
	Session.getCurrentSession().addCallback(callback)
	Session.getCurrentSession().open(AuthType.KAKAO_LOGIN_ALL, this) // 세션 오픈을 진행
}


private fun getKeyHash(context: Context) {
	try {
		val packageInfo = packageManager.getPackageInfo(packageName,PackageManager.GET_SIGNING_CERTIFICATES)
		val signatures = packageInfo.signingInfo.apkContentsSigners
		
        for(signature in signatures){
			val md: MessageDigest = MessageDigest.getInstance("SHA")
			md.update(signature.toByteArray())
			val key = String(Base64.encode(md.digest(), 0))
			Log.d(TAG,"Hash Key:$key")
		}
	}catch(e: Exception){
		Log.e("name not found", e.toString())
	}
}

 

 

 [ 방법#2 ] 

Utility.getKeyHash(context) 사용

private fun kakaoLoginStart(){
	Log.d(TAG, "LoginActivity - kakaoLoginStart() called")
	
        // keyHash 발급
	val keyHash = Utility.getKeyHash(this)
	Log.d(TAG, "KEY_HASH : $keyHash")
    
	// Kakao Login
	Session.getCurrentSession().addCallback(callback)
	Session.getCurrentSession().open(AuthType.KAKAO_LOGIN_ALL, this) // 세션 오픈을 진행
}

 

 

728x90

'Android Studio > Kotlin' 카테고리의 다른 글

[Kotlin][Firebase] Kakao Login 구현 #3  (6) 2021.08.24
[Kotlin][Firebase] Kakao Login 구현 #2  (1) 2021.08.24
[Kotlin][Firebase] Kakao Login 구현 #1  (0) 2021.08.23
Intent 예제  (0) 2021.08.10
Singleton  (0) 2021.08.05

BELATED ARTICLES

more