Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
circles-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Circles
circles-android
Commits
72896ce7
Commit
72896ce7
authored
10 months ago
by
Taras
Browse files
Options
Downloads
Patches
Plain Diff
Create key store provider
parent
d70ae153
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/java/org/futo/circles/core/provider/KeyStoreProvider.kt
+37
-0
37 additions, 0 deletions
...n/java/org/futo/circles/core/provider/KeyStoreProvider.kt
with
37 additions
and
0 deletions
core/src/main/java/org/futo/circles/core/provider/KeyStoreProvider.kt
0 → 100644
+
37
−
0
View file @
72896ce7
package
org.futo.circles.core.provider
import
org.matrix.android.sdk.api.extensions.tryOrNull
import
java.security.KeyStore
import
javax.crypto.SecretKey
import
javax.crypto.spec.SecretKeySpec
import
javax.inject.Inject
class
KeyStoreProvider
@Inject
constructor
()
{
private
val
keyStore
=
KeyStore
.
getInstance
(
"AndroidKeyStore"
)
fun
storeBsSpekePrivateKey
(
keyBytes
:
ByteArray
,
keyId
:
String
)
{
storeKey
(
keyBytes
,
"$ORG_FUTO_SSSS_KEY_PREFIX.$keyId"
)
}
fun
getBsSpekePrivateKey
(
keyId
:
String
):
ByteArray
?
=
getKey
(
"$ORG_FUTO_SSSS_KEY_PREFIX.$keyId"
)
private
fun
storeKey
(
keyBytes
:
ByteArray
,
alias
:
String
)
=
tryOrNull
{
val
secretKey
:
SecretKey
=
SecretKeySpec
(
keyBytes
,
"AES"
)
keyStore
.
load
(
null
)
val
protectionParameter
=
KeyStore
.
PasswordProtection
(
null
)
val
secretKeyEntry
=
KeyStore
.
SecretKeyEntry
(
secretKey
)
keyStore
.
setEntry
(
alias
,
secretKeyEntry
,
protectionParameter
)
}
private
fun
getKey
(
alias
:
String
):
ByteArray
?
=
tryOrNull
{
keyStore
.
load
(
null
)
val
secretKey
=
keyStore
.
getKey
(
alias
,
null
)
as
SecretKey
secretKey
.
encoded
}
companion
object
{
private
const
val
ORG_FUTO_SSSS_KEY_PREFIX
=
"org.futo.ssss.key"
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment