mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
first version credential provider
This commit is contained in:
@@ -9,7 +9,7 @@ android {
|
||||
ndkVersion "21.4.7075529"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 15
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 34
|
||||
multiDexEnabled true
|
||||
|
||||
@@ -40,7 +40,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
// Crypto
|
||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
|
||||
implementation 'org.bouncycastle:bcpkix-jdk18on:1.78.1'
|
||||
|
||||
testImplementation "androidx.test:runner:$android_test_version"
|
||||
}
|
||||
|
||||
43
crypto/src/main/java/com/kunzisoft/signature/Signature.kt
Normal file
43
crypto/src/main/java/com/kunzisoft/signature/Signature.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.kunzisoft.signature
|
||||
|
||||
import android.util.Log
|
||||
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
||||
import java.io.StringReader
|
||||
import java.security.PrivateKey
|
||||
import java.security.Security
|
||||
import java.security.Signature
|
||||
|
||||
import org.bouncycastle.openssl.PEMParser
|
||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter
|
||||
|
||||
object Signature {
|
||||
|
||||
init {
|
||||
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
|
||||
Security.addProvider(BouncyCastleProvider())
|
||||
}
|
||||
fun sign(privateKeyPem: String, message: ByteArray): ByteArray {
|
||||
val privateKey = createPrivateKey(privateKeyPem)
|
||||
val algorithmKey = privateKey.algorithm
|
||||
val algorithmSignature = when (algorithmKey) {
|
||||
"EC" -> "SHA256withECDSA"
|
||||
"ECDSA" -> "SHA256withECDSA"
|
||||
"RSA" -> "SHA256withRSA"
|
||||
else -> "no signature algorithms known"
|
||||
}
|
||||
val sig = Signature.getInstance(algorithmSignature, BouncyCastleProvider.PROVIDER_NAME)
|
||||
sig.initSign(privateKey)
|
||||
sig.update(message)
|
||||
return sig.sign()
|
||||
}
|
||||
|
||||
private fun createPrivateKey(privateKeyPem: String): PrivateKey {
|
||||
val targetReader = StringReader(privateKeyPem);
|
||||
val a = PEMParser(targetReader)
|
||||
val privateKeyInfo = a.readObject() as PrivateKeyInfo
|
||||
val privateKey = JcaPEMKeyConverter().getPrivateKey(privateKeyInfo)
|
||||
return privateKey
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user