We build a new generation human biometric authentication
platform that is easy to integrate into existing applications,
services or hardware products. We've designed an easy-to-use
REST API so integration will go smoothly!
For liveness
detection and anti-spoofing, we've developed
Auther Embedded.
This page describes the technical requirements that must be met to start using facial recognition technology in your applications and products. Please read all the sections in detail and strictly follow the requirements specified in the documentation and your integration will go quickly and smoothly. Sign-up and get a free plan for testing!
To send your first request, follow the steps below. For faster and more convenient testing, we recommend using Postman. Sign-up and get the API Key to authorize your requests.
Glossary
List of terms that are used in requests and responses:
Image requirements
The input image as base64-encoded bytes is required. For successful preparation of the Bade64-encoded image, before you sent requests, follow to the next criteria:
Image verification criteria
To successfully create a person_id, the image of the person you submit for enrollment will be verified for compliance with the following criteria:
Requests
All API requests must be sent in JSON format with the header:
{
"code":
"F_001",
"type":
"string",
"message":
"string"
}
Every request sent must be authenticated using the API Key. It should be sent in an HTTP header. You can create and manage your API Keys in the back-office. To get the API Key, you need to Sign-up and get a free plan for testing.
Required credentials
Base URL
Request headers
Response headers
To register a person in the system, please submit a Base64-encoded image of a a person on where the person looks straight ahead and also prepare the person_id you want to assign to this person in advance. When preparing the reference image, follow the requirements described above in the Image requirements section. Download "faceImage" sample.
Request headers
Go to request headersRequest Body
{
"faceImage": "string"
}
Response headers
Go to response headersStatus code 200
{
"personId": "string",
"created": "2020-09-03T16:05:08.938Z",
"updated": "2020-09-04T16:05:08.938Z"
}
Status code 400
{
"code": "string",
"message":
"string"
}
Codes and messages for response 400
To update the data of a person in the system, please submit
a Base64-encoded image of a a
person on where the person looks straight ahead and also
indicate the
person_id of the
person you want to assign new data to.
For preparing
the reference image, follow the requirements described above
in the
Image requirements
section.
Request headers
Go to request headersRequest Body
{
"faceImage": "base64format_string"
}
Response headers
Go to response headersStatus code 200
{
"personId": "string",
"created": "2020-09-03T16:05:08.938Z",
"updated": "2020-09-04T16:05:08.938Z"
}
Status code 400
{
"code": "string",
"message":
"string"
}
Codes and messages for response 400
HTTP Status code: 404
{
"code": "NF_001",
"message":
"Face not found in collection"
}
Codes and messages for response 404
HTTP Status code: 401, 403, 500
To remove a person's data from the system, just send the person_id parameter. The person's data will be deleted and the person_id will also be deleted.
Request headers
Go to request headersRequest Body
Response headers
Go to response headersHTTP Status code: 200
HTTP Status code: 400
{
"code": "string",
"message":
"string"
}
Codes and messages for response 400
HTTP Status code: 404
{
"code": "NF_001",
"message":
"Face not found in collection"
Codes and messages for response 404
HTTP Status codes: 401, 403, 500
To check if the person_id already exist in the system, just specify the path with person_id . If the person_id exist in response you will get the same person_id and information when person was created and updated.
Request headers
Go to request headersRequest Body
Response headers
Go to response headersHTTP Status code: 200
{
"personId": "string",
"created": "2020-09-03T16:05:08.938Z",
"updated": "2020-09-04T16:05:08.938Z"
}
HTTP Status code: 400
{
"code": "string",
"message":
"string"
}
Codes and messages for response 400
HTTP Status code: 404
{
"code": "NF_001",
"message":
"Face not found in collection"
Codes and messages for response 404
HTTP Status codes: 401, 403, 500
Submit the Base64-encoded image.
With this request, we start 1:N searching for
the most similar enrolled person in our system. The search
result will be
person_id, which
matches the searched one by 98%.
To improve the quality
and speed of recognition, follow the
image requirements for the
submitted images.
Download "faceImage" sample.
Request headers
Go to request headersRequest Body
{
"faceImage": "string"
}
Response headers
Go to response headersHTTP Status code: 200
{
"personId": "string",
"created": "2020-09-03T16:05:08.938Z",
"updated": "2020-09-04T16:05:08.938Z"
}
HTTP Status code: 400
{
"code": "string",
"message":
"string"
}
Codes and messages for response 400
HTTP Status code: 410
{
"code": "string",
"message":
"string"
}
Codes and messages for response 410
HTTP Status codes: 401, 403, 500
Comparison of the face of a person who declares that his face belongs to the known person_id. With this request, we start 1:1 matching for the enrolled person in our system. If the submitted person's face matches to 80% with the person's image that belongs to the declared person_id, then the verification result is successful.
Request headers
Go to request headersRequest Body
{
"faceImage": "string"
}
Response headers
Go to response headersHTTP Status code: 200
{
"personId": "string",
"created": "2020-09-03T16:05:08.938Z",
"updated": "2020-09-04T16:05:08.938Z"
}
HTTP Status code: 400
{
"code": "R_002",
"message":
"Request body exception"
}
Codes and messages for response 400
{
"personId": "string",
"created": "2020-09-03T16:05:08.938Z",
"updated": "2020-09-04T16:05:08.938Z"
}
HTTP Status code: 404
{
"code": "R_002",
"message":
"Request body exception"
}
Codes and messages for response 404
HTTP Status codes: 401, 403, 500
Compares the face on the sourceImage with
the largest face detected on the
targetImage.
By default, the submitted
sourceImage will be compared the
targetImage with the 80% of similarity
threshold. If you want to compare images with a custom
similarity threshold (for example, 98%), specify this number
in the request body
[option]. In response, you
get the value of the similarity images.
Request headers
Go to request headersRequest Body
{
"targetImage": "string",
"sourceImage": "string"
}
Request Body [option]
{
"targetImage": "string",
"sourceImage": "string",
"similarityThreshold": number
}
Response headers
Go to response headersHTTP Status code: 200
{
"similarity": value
}
HTTP Status code: 400
{
"code": "R_002",
"message":
"Request body exception"
}
Codes and messages for response 400
The custom 200 and 400 response codes are listed in the description for each request. Common server response codes are listed below.
HTTP Status code: 200
{
"personId": "string",
"created": "2020-09-03T16:05:08.938Z",
"updated": "2020-09-04T16:05:08.938Z"
}
HTTP Status code: 400
{
"code": "string",
"message": "string"
}
HTTP Status code: 401
{
"code": "string",
"message": "string"
}
HTTP Status code: 403
{
"code": "string",
"message": "string"
}
HTTP Status code: 404
{
"code": "string",
"message": "string"
}
HTTP Status code: 500
{
"code": "string",
"message": "string"
}
ENTERPRISE ONLY
This section describes how to use SHA-256 hashing and optional RSA-2048 encryption to sign requests. In this way, you can improve the security of data transmission. This option is available only for enterprise clients.
This section describes how to use SHA-256 hashing and optional RSA-2048 encryption to sign requests. In this way, you can improve the security of data transmission. This option is available only for enterprise clients.
Required credentials
Base URL
Request headers
Response headers
To create a request signature using hashing and encryption, follow the step-by-step instructions below:
To decrypt the request signature using hashing and encryption, follow the step-by-step instructions below:
| package com.riddletag.recognitionserver.example; | |
| import com.riddletag.recognitionserver.keys.SHA256Util; | |
| import okhttp3.*; | |
| import javax.crypto.BadPaddingException; | |
| import javax.crypto.Cipher; | |
| import javax.crypto.IllegalBlockSizeException; | |
| import javax.crypto.NoSuchPaddingException; | |
| import java.io.IOException; | |
| import java.nio.charset.StandardCharsets; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| import java.security.*; | |
| import java.security.spec.InvalidKeySpecException; | |
| import java.security.spec.X509EncodedKeySpec; | |
| import java.time.Instant; | |
| import java.util.Arrays; | |
| import java.util.Base64; | |
| public class OkHttpExample { | |
| private final OkHttpClient httpClient = new OkHttpClient(); | |
| private String accessKey = ""; | |
| private static String base64RsaPublicKey = ""; | |
| final static private MessageDigest digest; | |
| static { | |
| try { | |
| digest = MessageDigest.getInstance("SHA-256"); | |
| } catch (NoSuchAlgorithmException e) { | |
| throw new RuntimeException(e); | |
| } | |
| } | |
| public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); | |
| public static void | |
| main(String[] args) throws Exception { | |
| OkHttpExample obj = new OkHttpExample(); | |
| System.out.println("Testing 2 - Send Http POST request"); | |
| obj.sendPost(); | |
| } | |
| private void sendPost() throws IOException, NoSuchPaddingException, NoSuchAlgorithmException, | |
| InvalidKeyException, BadPaddingException, IllegalBlockSizeException { | |
| String host = "i4awvkpjw6.execute-api.eu-west-1.amazonaws.com/OugqX2kL4p"; | |
| String uri = | |
| "/profile/recognize"; | |
| String base64Photo = new String(Files.readAllBytes(Paths.get(""))); | |
| base64Photo = base64Photo.trim(); | |
| String body = "{\"base64Photo\": \"" + base64Photo + "\"}"; | |
| System.out.println("body: " + body); | |
| String timeStampMillis = ((Long) Instant.now().toEpochMilli()).toString(); | |
| String stringForSigning = getStringForSigning(host, uri, body, timeStampMillis); | |
| PublicKey publicKey = | |
| getPublicKey(base64RsaPublicKey); | |
| String sBase64EncryptedHash = getSignature(stringForSigning, publicKey); | |
| RequestBody requestBody = | |
| RequestBody.create(JSON, body); | |
| Request request = new Request.Builder() | |
| .url("https://" + host + uri).addHeader("Access-Key", accessKey).addHeader("Signature", | |
| sBase64EncryptedHash).addHeader("Timestamp", timeStampMillis).post(requestBody) | |
| .build(); | |
| Response response = httpClient.newCall(request).execute(); | |
| String sBase64EncryptedResponseHash = response.header("Signature"); | |
| System.out.println("sBase64EncryptedResponseHash: " + sBase64EncryptedResponseHash); | |
| ResponseBody responseBody = response.body(); | |
| String responseString = null; | |
| if (responseBody == null) { | |
| System.out.println("RESPONSE IS NULL"); | |
| } else { | |
| responseString = responseBody.string(); | |
| System.out.println("responseString: " + responseString); | |
| } | |
| String responseForSignature = getStringForSigning(host, uri, responseString, timeStampMillis); | |
| byte[] | |
| bHash = getHash(responseForSignature); | |
| String sBase64Hash = Base64.getEncoder().encodeToString(bHash); | |
| System.out.println("sBase64Hash: " + | |
| sBase64Hash); | |
| byte[] bEncryptedResponseHash = Base64.getDecoder().decode(sBase64EncryptedResponseHash); | |
| byte[] bResponseHash = decrypt(bEncryptedResponseHash, publicKey); | |
| String sBase64ResponseHash = Base64.getEncoder().encodeToString(bResponseHash); | |
| System.out.println("sBase64ResponseHash: " + sBase64ResponseHash); | |
| if (Arrays.equals(bHash, bResponseHash)) { | |
| System.out.println("Arrays are equals"); | |
| } else { | |
| System.out.println("Arrays aren't equals"); | |
| } | |
| } | |
| public static String getStringForSigning(String host, String uri, String body, String timeStampMillis) { | |
| return | |
| host + uri + body + timeStampMillis; | |
| } | |
| public static PublicKey getPublicKey(String base64PublicKey) { | |
| PublicKey publicKey = null; | |
| try { | |
| X509EncodedKeySpec keySpec = new | |
| X509EncodedKeySpec(Base64.getDecoder().decode(base64PublicKey.getBytes())); | |
| KeyFactory keyFactory = KeyFactory.getInstance("RSA"); | |
| publicKey = | |
| keyFactory.generatePublic(keySpec); | |
| return publicKey; | |
| } catch (NoSuchAlgorithmException e) { | |
| e.printStackTrace(); | |
| } catch (InvalidKeySpecException e) { | |
| e.printStackTrace(); | |
| } | |
| return publicKey; | |
| } | |
| public static String getSignature(String stringForSigning, PublicKey publicKey) { | |
| byte[] bHash = | |
| getHash(stringForSigning); | |
| byte[] bEncryptedHash = encrypt(bHash, publicKey); | |
| return Base64.getEncoder().encodeToString(bEncryptedHash); | |
| } | |
| public static byte[] getHash(String sForHashing) { | |
| byte[] bFoHashing = sForHashing.getBytes(StandardCharsets.UTF_8); | |
| return | |
| SHA256Util.digest.digest(bFoHashing); | |
| } | |
| public static byte[] encrypt(byte[] data, Key key) { | |
| return doFinal(data, Cipher.ENCRYPT_MODE, key); | |
| } | |
| public static byte[] decrypt(byte[] data, Key key) { | |
| return doFinal(data, Cipher.DECRYPT_MODE, key); | |
| } | |
| private static byte[] doFinal(byte[] data, int mode, Key key) { | |
| try { | |
| Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); | |
| cipher.init(mode, key); | |
| return cipher.doFinal(data); | |
| } catch (Exception e) { | |
| throw new RuntimeException(); | |
| } | |
| } | |
| } |
| package com.riddletag.recognitionserver.example; | |
| import com.riddletag.recognitionserver.keys.SHA256Util; | |
| import okhttp3.*; | |
| import javax.crypto.BadPaddingException; | |
| import javax.crypto.Cipher; | |
| import javax.crypto.IllegalBlockSizeException; | |
| import javax.crypto.NoSuchPaddingException; | |
| import java.io.IOException; | |
| import java.nio.charset.StandardCharsets; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| import java.security.*; | |
| import java.security.spec.InvalidKeySpecException; | |
| import java.security.spec.X509EncodedKeySpec; | |
| import java.time.Instant; | |
| import java.util.Arrays; | |
| import java.util.Base64; | |
| public class OkHttpExample { | |
| private final OkHttpClient httpClient = new OkHttpClient(); | |
| private String accessKey = ""; | |
| private static String base64RsaPublicKey = ""; | |
| final static private MessageDigest digest; | |
| static { | |
| try { | |
| digest = MessageDigest.getInstance("SHA-256"); | |
| } catch (NoSuchAlgorithmException e) { | |
| throw new RuntimeException(e); | |
| } | |
| } | |
| public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); | |
| public static void | |
| main(String[] args) throws Exception { | |
| OkHttpExample obj = new OkHttpExample(); | |
| System.out.println("Testing 2 - Send Http POST request"); | |
| obj.sendPost(); | |
| } | |
| private void sendPost() throws IOException, NoSuchPaddingException, NoSuchAlgorithmException, | |
| InvalidKeyException, BadPaddingException, IllegalBlockSizeException { | |
| String host = "i4awvkpjw6.execute-api.eu-west-1.amazonaws.com/OugqX2kL4p"; | |
| String uri = | |
| "/profile/recognize"; | |
| String base64Photo = new String(Files.readAllBytes(Paths.get(""))); | |
| base64Photo = base64Photo.trim(); | |
| String body = "{\"base64Photo\": \"" + base64Photo + "\"}"; | |
| System.out.println("body: " + body); | |
| String timeStampMillis = ((Long) Instant.now().toEpochMilli()).toString(); | |
| String stringForSigning = getStringForSigning(host, uri, body, timeStampMillis); | |
| PublicKey publicKey = | |
| getPublicKey(base64RsaPublicKey); | |
| String sBase64EncryptedHash = getSignature(stringForSigning, publicKey); | |
| RequestBody requestBody = | |
| RequestBody.create(JSON, body); | |
| Request request = new Request.Builder() | |
| .url("https://" + host + uri).addHeader("Access-Key", accessKey).addHeader("Signature", | |
| sBase64EncryptedHash).addHeader("Timestamp", timeStampMillis).post(requestBody) | |
| .build(); | |
| Response response = httpClient.newCall(request).execute(); | |
| String sBase64EncryptedResponseHash = response.header("Signature"); | |
| System.out.println("sBase64EncryptedResponseHash: " + sBase64EncryptedResponseHash); | |
| ResponseBody responseBody = response.body(); | |
| String responseString = null; | |
| if (responseBody == null) { | |
| System.out.println("RESPONSE IS NULL"); | |
| } else { | |
| responseString = responseBody.string(); | |
| System.out.println("responseString: " + responseString); | |
| } | |
| String responseForSignature = getStringForSigning(host, uri, responseString, timeStampMillis); | |
| byte[] | |
| bHash = getHash(responseForSignature); | |
| String sBase64Hash = Base64.getEncoder().encodeToString(bHash); | |
| System.out.println("sBase64Hash: " + | |
| sBase64Hash); | |
| byte[] bEncryptedResponseHash = Base64.getDecoder().decode(sBase64EncryptedResponseHash); | |
| byte[] bResponseHash = decrypt(bEncryptedResponseHash, publicKey); | |
| String sBase64ResponseHash = Base64.getEncoder().encodeToString(bResponseHash); | |
| System.out.println("sBase64ResponseHash: " + sBase64ResponseHash); | |
| if (Arrays.equals(bHash, bResponseHash)) { | |
| System.out.println("Arrays are equals"); | |
| } else { | |
| System.out.println("Arrays aren't equals"); | |
| } | |
| } | |
| public static String getStringForSigning(String host, String uri, String body, String timeStampMillis) { | |
| return | |
| host + uri + body + timeStampMillis; | |
| } | |
| public static PublicKey getPublicKey(String base64PublicKey) { | |
| PublicKey publicKey = null; | |
| try { | |
| X509EncodedKeySpec keySpec = new | |
| X509EncodedKeySpec(Base64.getDecoder().decode(base64PublicKey.getBytes())); | |
| KeyFactory keyFactory = KeyFactory.getInstance("RSA"); | |
| publicKey = | |
| keyFactory.generatePublic(keySpec); | |
| return publicKey; | |
| } catch (NoSuchAlgorithmException e) { | |
| e.printStackTrace(); | |
| } catch (InvalidKeySpecException e) { | |
| e.printStackTrace(); | |
| } | |
| return publicKey; | |
| } | |
| public static String getSignature(String stringForSigning, PublicKey publicKey) { | |
| byte[] bHash = | |
| getHash(stringForSigning); | |
| byte[] bEncryptedHash = encrypt(bHash, publicKey); | |
| return Base64.getEncoder().encodeToString(bEncryptedHash); | |
| } | |
| public static byte[] getHash(String sForHashing) { | |
| byte[] bFoHashing = sForHashing.getBytes(StandardCharsets.UTF_8); | |
| return | |
| SHA256Util.digest.digest(bFoHashing); | |
| } | |
| public static byte[] encrypt(byte[] data, Key key) { | |
| return doFinal(data, Cipher.ENCRYPT_MODE, key); | |
| } | |
| public static byte[] decrypt(byte[] data, Key key) { | |
| return doFinal(data, Cipher.DECRYPT_MODE, key); | |
| } | |
| private static byte[] doFinal(byte[] data, int mode, Key key) { | |
| try { | |
| Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); | |
| cipher.init(mode, key); | |
| return cipher.doFinal(data); | |
| } catch (Exception e) { | |
| throw new RuntimeException(); | |
| } | |
| } | |
| } |
| package com.riddletag.recognitionserver.example; | |
| import com.riddletag.recognitionserver.keys.SHA256Util; | |
| import okhttp3.*; | |
| import javax.crypto.BadPaddingException; | |
| import javax.crypto.Cipher; | |
| import javax.crypto.IllegalBlockSizeException; | |
| import javax.crypto.NoSuchPaddingException; | |
| import java.io.IOException; | |
| import java.nio.charset.StandardCharsets; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| import java.security.*; | |
| import java.security.spec.InvalidKeySpecException; | |
| import java.security.spec.X509EncodedKeySpec; | |
| import java.time.Instant; | |
| import java.util.Arrays; | |
| import java.util.Base64; | |
| public class OkHttpExample { | |
| private final OkHttpClient httpClient = new OkHttpClient(); | |
| private String accessKey = ""; | |
| private static String base64RsaPublicKey = ""; | |
| final static private MessageDigest digest; | |
| static { | |
| try { | |
| digest = MessageDigest.getInstance("SHA-256"); | |
| } catch (NoSuchAlgorithmException e) { | |
| throw new RuntimeException(e); | |
| } | |
| } | |
| public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); | |
| public static void | |
| main(String[] args) throws Exception { | |
| OkHttpExample obj = new OkHttpExample(); | |
| System.out.println("Testing 2 - Send Http POST request"); | |
| obj.sendPost(); | |
| } | |
| private void sendPost() throws IOException, NoSuchPaddingException, NoSuchAlgorithmException, | |
| InvalidKeyException, BadPaddingException, IllegalBlockSizeException { | |
| String host = "i4awvkpjw6.execute-api.eu-west-1.amazonaws.com/OugqX2kL4p"; | |
| String uri = | |
| "/profile/recognize"; | |
| String base64Photo = new String(Files.readAllBytes(Paths.get(""))); | |
| base64Photo = base64Photo.trim(); | |
| String body = "{\"base64Photo\": \"" + base64Photo + "\"}"; | |
| System.out.println("body: " + body); | |
| String timeStampMillis = ((Long) Instant.now().toEpochMilli()).toString(); | |
| String stringForSigning = getStringForSigning(host, uri, body, timeStampMillis); | |
| PublicKey publicKey = | |
| getPublicKey(base64RsaPublicKey); | |
| String sBase64EncryptedHash = getSignature(stringForSigning, publicKey); | |
| RequestBody requestBody = | |
| RequestBody.create(JSON, body); | |
| Request request = new Request.Builder() | |
| .url("https://" + host + uri).addHeader("Access-Key", accessKey).addHeader("Signature", | |
| sBase64EncryptedHash).addHeader("Timestamp", timeStampMillis).post(requestBody) | |
| .build(); | |
| Response response = httpClient.newCall(request).execute(); | |
| String sBase64EncryptedResponseHash = response.header("Signature"); | |
| System.out.println("sBase64EncryptedResponseHash: " + sBase64EncryptedResponseHash); | |
| ResponseBody responseBody = response.body(); | |
| String responseString = null; | |
| if (responseBody == null) { | |
| System.out.println("RESPONSE IS NULL"); | |
| } else { | |
| responseString = responseBody.string(); | |
| System.out.println("responseString: " + responseString); | |
| } | |
| String responseForSignature = getStringForSigning(host, uri, responseString, timeStampMillis); | |
| byte[] | |
| bHash = getHash(responseForSignature); | |
| String sBase64Hash = Base64.getEncoder().encodeToString(bHash); | |
| System.out.println("sBase64Hash: " + | |
| sBase64Hash); | |
| byte[] bEncryptedResponseHash = Base64.getDecoder().decode(sBase64EncryptedResponseHash); | |
| byte[] bResponseHash = decrypt(bEncryptedResponseHash, publicKey); | |
| String sBase64ResponseHash = Base64.getEncoder().encodeToString(bResponseHash); | |
| System.out.println("sBase64ResponseHash: " + sBase64ResponseHash); | |
| if (Arrays.equals(bHash, bResponseHash)) { | |
| System.out.println("Arrays are equals"); | |
| } else { | |
| System.out.println("Arrays aren't equals"); | |
| } | |
| } | |
| public static String getStringForSigning(String host, String uri, String body, String timeStampMillis) { | |
| return | |
| host + uri + body + timeStampMillis; | |
| } | |
| public static PublicKey getPublicKey(String base64PublicKey) { | |
| PublicKey publicKey = null; | |
| try { | |
| X509EncodedKeySpec keySpec = new | |
| X509EncodedKeySpec(Base64.getDecoder().decode(base64PublicKey.getBytes())); | |
| KeyFactory keyFactory = KeyFactory.getInstance("RSA"); | |
| publicKey = | |
| keyFactory.generatePublic(keySpec); | |
| return publicKey; | |
| } catch (NoSuchAlgorithmException e) { | |
| e.printStackTrace(); | |
| } catch (InvalidKeySpecException e) { | |
| e.printStackTrace(); | |
| } | |
| return publicKey; | |
| } | |
| public static String getSignature(String stringForSigning, PublicKey publicKey) { | |
| byte[] bHash = | |
| getHash(stringForSigning); | |
| byte[] bEncryptedHash = encrypt(bHash, publicKey); | |
| return Base64.getEncoder().encodeToString(bEncryptedHash); | |
| } | |
| public static byte[] getHash(String sForHashing) { | |
| byte[] bFoHashing = sForHashing.getBytes(StandardCharsets.UTF_8); | |
| return | |
| SHA256Util.digest.digest(bFoHashing); | |
| } | |
| public static byte[] encrypt(byte[] data, Key key) { | |
| return doFinal(data, Cipher.ENCRYPT_MODE, key); | |
| } | |
| public static byte[] decrypt(byte[] data, Key key) { | |
| return doFinal(data, Cipher.DECRYPT_MODE, key); | |
| } | |
| private static byte[] doFinal(byte[] data, int mode, Key key) { | |
| try { | |
| Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); | |
| cipher.init(mode, key); | |
| return cipher.doFinal(data); | |
| } catch (Exception e) { | |
| throw new RuntimeException(); | |
| } | |
| } | |
| } |