Local certificate
Generating a local certificate
- Typescript
- Python
- Java
- PHP
- Golang
import {
KeyClient,
KeyType,
LocalCertificateParams,
SubjectCertificateParams,
} from '@bloock/sdk';
const keyClient = new KeyClient();
// Load a managed key
const _certificate = await keyClient.newLocalCertificate(
new LocalCertificateParams(
KeyType.Rsa2048,
new SubjectCertificateParams('Bloock'),
'password',
2
)
);
from bloock.client.key import KeyClient
from bloock.entity.key.key_type import KeyType
from bloock.entity.key.local_certificate_params import LocalCertificateParams
from bloock.entity.key.subject_certificate_params import SubjectCertificateParams
if __name__ == "__main__":
key_client = KeyClient()
key_type = KeyType.Rsa2048
subject_params = SubjectCertificateParams(
"Common name",
"Organization",
"Organization Unit",
"Location",
"State",
"US"
)
params = LocalCertificateParams(key_type, subject_params, "password", 2)
local_certificate = key_client.new_local_certificate(params)
import com.bloock.sdk.client.KeyClient;
import com.bloock.sdk.entity.key.*;
public class NewLocalCertificate {
public static void main(String[] args) throws Exception {
KeyClient keyClient = new KeyClient();
// Create a local certificate
LocalCertificate certificate = keyClient.newLocalCertificate(new LocalCertificateParams(
KeyType.Rsa2048,
new SubjectCertificateParams(
"BLOOCK",
"Organization",
"Organization Unit",
"Location",
"State",
"Country"),
"password",
12));
}
}
<?php
require "./vendor/autoload.php";
use Bloock\Client\KeyClient;
use Bloock\Entity\Key\KeyType;
use Bloock\Entity\Key\SubjectCertificateParams;
use Bloock\Entity\Key\LocalCertificateArgs;
$keyClient = new KeyClient();
$keyType = KeyType::Bjj;
$subjectParams = new SubjectCertificateParams(
"Common Name",
"Organization",
"Organization Unit",
"Location",
"State",
"US"
);
$params = new LocalCertificateArgs($keyType, $subjectParams, "password", 2);
$certificate = $keyClient->newLocalCertificate($params);
package main
import (
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity/key"
)
func main() {
keyClient := client.NewKeyClient()
_, _ = keyClient.NewLocalCertificate(key.LocalCertificateParams{
KeyType: key.Rsa2048,
Password: "a password",
Subject: key.SubjectCertificateParams{
CommonName: "BLOOCK",
},
ExpirationMonths: 12,
})
}
Loading an existing local certificate
- Typescript
- Python
- Java
- PHP
- Golang
import { KeyClient } from '@bloock/sdk';
import * as fs from 'fs';
import path from 'path';
const keyClient = new KeyClient();
// Load a local certificate
const dirPath = path.join(__dirname, '/certificate.p12');
const buffer = fs.readFileSync(dirPath);
const _certificate = await keyClient.loadLocalCertificate(buffer, 'password');
import os
from bloock.client.key import KeyClient
if __name__ == "__main__":
key_client = KeyClient()
current_directory = os.getcwd()
file_path = current_directory + "certificate.p12"
with open(file_path, 'rb') as file:
file_bytes = file.read()
local_certificate = key_client.load_local_certificate(file_bytes, "password")
import com.bloock.sdk.client.KeyClient;
import com.bloock.sdk.entity.key.LocalCertificate;
import java.io.File;
import java.io.FileInputStream;
public class LoadLocalCertificate {
public static void main(String[] args) throws Exception {
KeyClient keyClient = new KeyClient();
// Retrieve P12 certificate from filesystem
File file = new File("./certificate.p12");
int fileSize = (int) file.length();
byte[] bytes = new byte[fileSize];
try (FileInputStream inputStream = new FileInputStream(file)) {
inputStream.read(bytes);
}
// Load a local certificate
LocalCertificate key = keyClient.loadLocalCertificate(bytes, "p12 password");
}
}
<?php
require "./vendor/autoload.php";
use Bloock\Client\KeyClient;
$keyClient = new KeyClient();
$currentDirectory = getcwd();
$fileContents = file_get_contents($currentDirectory . "certificate.p12");
if ($fileContents !== false) {
$byteArray = unpack('C*', $fileContents);
if ($byteArray !== false) {
$certificate = $keyClient->loadLocalCertificate($byteArray, "password");
}
}
package main
import (
"log"
"os"
"github.com/bloock/bloock-sdk-go/v2/client"
)
func main() {
keyClient := client.NewKeyClient()
cert, err := os.ReadFile("certificate.p12")
if err != nil {
log.Println(err)
}
_, _ = keyClient.LoadLocalCertificate(cert, "password")
}