Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bot2600
Created January 11, 2017 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bot2600/e4a68aef9127944dfb2ace636795762f to your computer and use it in GitHub Desktop.
Save bot2600/e4a68aef9127944dfb2ace636795762f to your computer and use it in GitHub Desktop.
let KeyStore = java.security.KeyStore
let Cipher = javax.crypto.Cipher
let KeyGenerator = javax.crypto.KeyGenerator
let KeyProperties = android.security.keystore.KeyProperties
let KeyGenParameterSpec = android.security.keystore.KeyGenParameterSpec
let FingerprintManager = android.hardware.fingerprint.FingerprintManager
export class TestClass {
private keyguardManager = utils.ad.getApplicationContext().getSystemService("keyguard")
private fingerprintManager = utils.ad.getApplicationContext().getSystemService("fingerprint")
private REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1001
private KEY_NAME = 'fingerprintauth'
private KEYSTORE_NAME = 'AndroidKeyStore'
allInOneTest() {
let keyStore = KeyStore.getInstance(this.KEYSTORE_NAME)
keyStore.load(null)
var keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, this.KEYSTORE_NAME)
keyGenerator.init(
new KeyGenParameterSpec.Builder(this.KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes([KeyProperties.BLOCK_MODE_CBC])
.setUserAuthenticationRequired(false)
.setEncryptionPaddings([KeyProperties.ENCRYPTION_PADDING_PKCS7])
.build()
)
keyGenerator.generateKey()
let secretKey = keyStore.getKey(this.KEY_NAME, null)
let cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7)
cipher.init(Cipher.ENCRYPT_MODE, secretKey)
let callbackClass = FingerprintManager.AuthenticationCallback.extend({
onAuthenticationError(errorCode, errString) {
console.log("error")
},
onAuthenticationHelp(helpCode, helpString) {
},
onAuthenticationSucceeded(result) {
},
onAuthenticationFailed() {
}
})
let callbackInstance = new callbackClass()
let cancellationSignal = new android.os.CancellationSignal()
let cryptoObject = new FingerprintManager.CryptoObject(cipher)
this.fingerprintManager.authenticate(cryptoObject, cancellationSignal, 0, callbackInstance, null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment