BLOOCK Docs
Search…
⌃K

Decrypt

AES

JavaScript
Java
Python
Golang
PHP
const { AesDecrypter, AesEncrypter, KeyClient, EncryptionClient, RecordClient } = require("@bloock/sdk");
let payload = "This will be encrypted";
// encryption ...
const recordClient = new RecordClient();
const keyClient = new KeyClient();
let key = await keyClient.newLocalKey(KeyType.Aes256);
// To decrypt a record during the building process
// we build a record from the encrypted record and add a decrypter
let decryptedRecord = await recordClient.fromRecord(encryptedRecord)
.withDecrypter(new AesDecrypter(key))
.build();
// To decrypt an already encrypted record independently
const encryptionClient = new EncryptionClient();
decryptedRecord = await encryptionClient.decrypt(encryptedRecord, new AesDecrypter(key));
let decryptedPayload = decryptedRecord.retrieve();
console.log(`Decryption successfully`);
console.log(
`Decrypted payload: ${new TextDecoder().decode(decryptedPayload)}`
);
import com.bloock.sdk.client.EncryptionClient;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.AesDecrypter;
import com.bloock.sdk.entity.AesEncrypter;
import com.bloock.sdk.entity.Record;
import java.nio.charset.StandardCharsets;
public class App {
public static void main(String[] args) throws Exception {
String payload = "This will be encrypted";
// encryption ...
System.out.println("Trying to decrypt with the valid password");
RecordClient recordClient = new RecordClient();
KeyClient keyClient = new KeyClient();
LocalKey localKey = keyClient.newLocalKey(KeyType.Aes256);
// To decrypt a record during the building process
// we build a record from the encrypted record and add a decrypter
Record decryptedRecord = recordClient.fromRecord(encryptedRecord)
.withDecrypter(new AesDecrypter(localKey))
.build();
// To decrypt an already encrypted record independently
EncryptionClient encryptionClient = new EncryptionClient();
decryptedRecord = encryptionClient.decrypt(encryptedRecord, new AesDecrypter(localKey));
System.out.println(
"Decrypted payload: " + new String(decryptedRecord.retrieve(), StandardCharsets.UTF_8));
}
}
from bloock.entity.decrypter import AesDecrypter
from bloock.entity.encrypter import AesEncrypter
from bloock.client.encryption import EncryptionClient
from bloock.client.record import RecordClient
payload = "This will be encrypted"
record_client = RecordClient()
encryption_client = EncryptionClient()
key_client = KeyClient()
# encryption ...
print("Trying to decrypt with the valid password")
key = key_client.new_local_key(KeyType.Aes256)
# To decrypt a record during the building process
# we build a record from the encrypted record and add a decrypter
record_client = (
record_client.from_record(encrypted_record)
.with_decrypter(AesDecrypter(DecrypterArgs(key)))
.build()
)
# To decrypt an already encrypted record independently
decrypted_record = encryption_client.decrypt(
encrypted_record, AesDecrypter(DecrypterArgs(key))
)
print(f"Decryption successful")
print(f'Decrypted payload: "{decrypted_record.retrieve().decode()}"')
package main
import (
"fmt"
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity"
)
func main() {
payload := "This will be encrypted"
recordClient := client.NewRecordClient()
encryptionClient := client.NewEncryptionClient()
keyClient := client.NewKeyClient()
key, err := keyClient.NewLocalKey(key.Aes256)
if err != nil {
log.Println(err)
}
// encryption ...
fmt.Println("Trying to decrypt with the valid password")
// To decrypt a record during the building process
// we build a record from the encrypted record and add a decrypter
decryptedRecord, err := recordClient.FromRecord(encryptedRecord).
WithDecrypter(entity.NewAesDecrypter(encryption.DecrypterArgs{
LocalKey: &key,
})).
Build()
if err != nil {
log.Println(err)
}
// To decrypt an already encrypted record independently
decryptedRecord, err = encryptionClient.Decrypt(encryptedRecord, entity.NewAesDecrypter(encryption.DecrypterArgs{
LocalKey: &key,
}))
if err != nil {
log.Println(err)
}
fmt.Println("Decryption successful")
fmt.Println("Decrypted payload: " + string(decryptedRecord.Retrieve()))
}
<?php
require "./vendor/autoload.php";
use Bloock\Bloock;
use Bloock\Client\EncryptionClient;
use Bloock\Client\KeyClient;
use Bloock\Client\RecordClient;
use Bloock\Entity\Encryption\AesDecrypter;
use Bloock\Entity\Encryption\DecrypterArgs;
use Bloock\Entity\Key\KeyType;
Bloock::$apiKey = getenv("API_KEY");
$keyClient = new KeyClient();
$payload = "This will be encrypted";
$key = $keyClient->newLocalKey(KeyType::Aes256);
// encryption ...
$recordClient = new RecordClient();
$decryptedRecord = $recordClient->fromRecord($encryptedRecord)
->withDecrypter(new AesDecrypter(new DecrypterArgs($key)))
->build();
$encryptionClient = new EncryptionClient();
$decryptedRecord = $encryptionClient->decrypt($encryptedRecord, new AesDecrypter(new DecrypterArgs($key)));
$decryptedPayload = $decryptedRecord->retrieve();
print "Decryption successfully\n";
$decrypted = implode(array_map("chr", $decryptedPayload));
print "Decrypted payload: $decrypted";

RSA

JavaScript
Java
Python
Golang
PHP
const { EncryptionClient, RecordClient, KeyClient, RsaEncrypter, RsaDecrypter } = require("@bloock/sdk");
let payload = "This will be encrypted";
let client = new BloockClient();
// encryption ...
const recordClient = new RecordClient();
const keyClient = new KeyClient();
let key = await keyClient.newLocalKey(KeyType.Rsa2048);
// To decrypt a record during the building process
// we build a record from the encrypted record and add a decrypter
let decryptedRecord = await recordClient.fromRecord(encryptedRecord)
.withDecrypter(new RsaDecrypter(key))
.build();
// To decrypt an already encrypted record independently
const encryptionClient = new EncryptionClient();
decryptedRecord = await encryptionClient.decrypt(encryptedRecord, new RsaDecrypter(key));
let decryptedPayload = decryptedRecord.retrieve();
console.log(`Decryption successfully`);
console.log(
`Decrypted payload: ${new TextDecoder().decode(decryptedPayload)}`
);
import com.bloock.sdk.client.EncryptionClient;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.Record;
import com.bloock.sdk.entity.RsaDecrypter;
import com.bloock.sdk.entity.RsaEncrypter;
import com.bloock.sdk.entity.RsaKeyPair;
import java.nio.charset.StandardCharsets;
public class App {
public static void main(String[] args) throws Exception {
String payload = "This will be encrypted";
// encryption ...
RecordClient recordClient = new RecordClient();
KeyClient keyClient = new KeyClient();
LocalKey localKey = keyClient.newLocalKey(KeyType.Rsa2048);
// To decrypt a record during the building process
// we build a record from the encrypted record and add a decrypter
Record decryptedRecord = recordClient.fromRecord(encryptedRecord)
.withDecrypter(new RsaDecrypter(localKey))
.build();
// To decrypt an already encrypted record independently
EncryptionClient encryptionClient = new EncryptionClient();
decryptedRecord = encryptionClient.decrypt(encryptedRecord, new RsaDecrypter(localKey))
System.out.println(
"Decrypted payload: " + new String(decryptedRecord.retrieve(), StandardCharsets.UTF_8));
}
}
from bloock.entity.decrypter import RsaDecrypter
from bloock.entity.encrypter import RsaEncrypter
from bloock.client.encryption import EncryptionClient
from bloock.client.record import RecordClient
payload = "This will be encrypted"
record_client = RecordClient()
encryption_client = EncryptionClient()
key_client = KeyClient()
# encryption ...
print("Trying to decrypt with the valid password")
key = key_client.new_local_key(KeyType.Rsa2048)
# To decrypt a record during the building process
# we build a record from the encrypted record and add a decrypter
record_client = (
record_client.from_record(encrypted_record)
.with_decrypter(RsaDecrypter(DecrypterArgs(key)))
.build()
)
# To decrypt an already encrypted record independently
decrypted_record = encryption_client.decrypt(
encrypted_record, RsaDecrypter(DecrypterArgs(key))
)
print(f"Decryption successful")
print(f'Decrypted payload: "{decrypted_record.retrieve().decode()}"')
package main
import (
"fmt"
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity"
)
func main() {
payload := "This will be encrypted"
recordClient := client.NewRecordClient()
encryptionClient := client.NewEncryptionClient()
keyClient := client.NewKeyClient()
key, err := keyClient.NewLocalKey(key.Rsa2048)
if err != nil {
log.Println(err)
}
// encryption ...
fmt.Println("Trying to decrypt with the valid password")
// To decrypt a record during the building process
// we build a record from the encrypted record and add a decrypter
decryptedRecord, err := recordClient.FromRecord(encryptedRecord).
WithDecrypter(entity.NewRsaDecrypter(encryption.DecrypterArgs{
LocalKey: &key,
})).
Build()
if err != nil {
log.Println(err)
}
// To decrypt an already encrypted record independently
decryptedRecord, err = encryptionClient.Decrypt(encryptedRecord, entity.NewRsaDecrypter(encryption.DecrypterArgs{
LocalKey: &key,
}))
if err != nil {
log.Println(err)
}
fmt.Println("Decryption successful")
fmt.Println("Decrypted payload: " + string(decryptedRecord.Retrieve()))
}
<?php
require "./vendor/autoload.php";
use Bloock\Bloock;
use Bloock\Client\EncryptionClient;
use Bloock\Client\KeyClient;
use Bloock\Client\RecordClient;
use Bloock\Entity\Encryption\DecrypterArgs;
use Bloock\Entity\Encryption\RsaDecrypter;
use Bloock\Entity\Key\KeyType;
Bloock::$apiKey = getenv("API_KEY");
$keyClient = new KeyClient();
$payload = "This will be encrypted";
$key = $keyClient->newLocalKey(KeyType::Rsa2048);
// encryption ...
$recordClient = new RecordClient();
$decryptedRecord = $recordClient->fromRecord($encryptedRecord)
->withDecrypter(new RsaDecrypter(new DecrypterArgs($key)))
->build();
$encryptionClient = new EncryptionClient();
$decryptedRecord = $encryptionClient->decrypt($encryptedRecord, new RsaDecrypter(new DecrypterArgs($key)));
$decryptedPayload = $decryptedRecord->retrieve();
print "Decryption successfully\n";
$decrypted = implode(array_map("chr", $decryptedPayload));
print "Decrypted payload: $decrypted";