BCrypter - Esempi
Cifratura e decifratura
using B.BSecurity;
string encrypted = BCrypter.Encrypt("testo riservato");
string clearText = BCrypter.Decrypt(encrypted);
Una stringa vuota viene restituita come stringa vuota. Decrypt tenta anche la compatibilità con BCrypterLegacy quando il formato corrente non può essere decifrato.
Password di cifratura applicativa
using B.BSecurity;
try
{
BCrypter.SetCryptPassword("chiave-letta-da-un-secret-store");
string encrypted = BCrypter.Encrypt("valore applicativo");
string clearText = BCrypter.Decrypt(encrypted);
}
finally
{
BCrypter.ResetCryptPassword();
}
La password di cifratura è statica e influenza le chiamate successive dell'intero processo. Non cambiarla contemporaneamente da flussi differenti e ripristinarla quando il cambio è temporaneo.
Chiave temporale
using B.BSecurity;
string encryptedKey = BCrypter.Encrypt("shared-key");
string firstToken = BCrypter.GetSecurePassword(encryptedKey);
string secondToken = BCrypter.GetSecurePassword(encryptedKey);
bool valid = BCrypter.CheckSecurePassword(firstToken, secondToken, TimeExpired: 5);
GetSecurePassword aggiunge data e ora UTC, con precisione al minuto, al valore decifrato. CheckSecurePassword verifica che la chiave sia uguale e che la distanza temporale non superi TimeExpired minuti.
Questo è il meccanismo usato dalle Web API B-Arts con l'header B-SECURE-KEY. Per l'intero flusso client/server consultare B.BWebApi/BApiServiceSecureKey.Examples.md.
BCrypteroffre cifratura compatibile con l'ecosistema B-Arts. Non deve essere descritto come password hashing e non sostituisce un sistema dedicato alla conservazione delle password degli utenti.
