Enkripsi file Excel

Sandi Protect Excel(XLS, XLSX) nggunakake C# .NET

Excel minangka alat sing akeh digunakake kanggo ngatur lan nganalisa data. Nanging, kadhangkala data sing ana ing file Excel bisa sensitif utawa rahasia, lan penting kanggo nglindhungi saka akses sing ora sah. Kanthi nglindhungi sandi lan ngenkripsi file Excel, sampeyan bisa ngamanake data lan nyegah supaya ora tiba ing tangan sing salah. Fitur iki penting banget kanggo bisnis lan organisasi sing ngurusi informasi rahasia. Ing artikel iki, kita bakal nuduhake sampeyan carane kanggo sandi nglindhungi lan encrypt file Excel nggunakake C# .NET, supaya sampeyan bisa nyimpen data aman lan nglindhungi privasi.

API kanggo Sandi Nglindhungi File Excel

Aspose.Cells Cloud SDK kanggo .NET minangka alat apik tenan sing ngidini pangembang kanthi gampang nambah proteksi sandhi menyang file Excel. Kanthi fitur iki, sampeyan bisa nglindhungi data sensitif lan nyegah akses ora sah menyang file sampeyan. Proteksi sandhi penting kanggo bisnis lan pangguna individu, sing cukup prihatin babagan privasi informasi kasebut. API iki nggampangake nambahake proteksi sandhi menyang file Excel, tanpa mbutuhake kodhe rumit utawa piranti lunak tambahan.

Saiki goleki Aspose.Cells-Cloud ing “NuGet packages manager” lan klik tombol “Add Package”. Kapindho, yen sampeyan ora duwe akun liwat Cloud Dashboard, mangga gawe akun gratis kanthi nggunakake alamat email sing bener lan entuk kredensial pribadi sampeyan.

Enkripsi File Excel nggunakake C#

Coba gunakake potongan kode ing ngisor iki kanggo nambah sandhi menyang Buku Kerja Excel.

Kita wis nggunakake XOR minangka jinis enkripsi lan salah siji saka nilai ing ngisor iki bisa diutus kanggo EncryptionType property

  • XOR
  • Kompatibel
  • EnhancedCryptographicProviderV1
  • Panyedhiya Kriptografi Kuwat
// Kanggo conto lengkap lan file data, bukak 
https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet/

// Entuk kredensial klien saka https://dashboard.aspose.cloud/
string clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
string clientID = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
        
// nggawe conto CellsApi nalika ngliwati ClientID lan ClientSecret
CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

// buku kerja Excle pisanan ing drive
string input_Excel = "myDocument.xlsx";

try
{
    // maca file Excel menyang conto File
    var file = System.IO.File.OpenRead(input_Excel);

    // upload Excel menyang panyimpenan maya
    cellsInstance.UploadFile(input_Excel, File.OpenRead(input_Excel));
    
    // Nggawe obyek panjalukan Enkripsi lan nemtokake jinis enkripsi lan rincian sandhi
    WorkbookEncryptionRequest encryption = new WorkbookEncryptionRequest();
    encryption.Password = "123456";
    encryption.KeyLength = 128;
    encryption.EncryptionType = "XOR";
                    
    // miwiti operasi konversi
    var response = cellsInstance.CellsWorkbookPostEncryptDocument(input_Excel, encryption, null);

    // print pesen sukses yen concatenation sukses
    if (response != null && response.Equals("OK"))
    {
        Console.WriteLine("Excel is successfully Encrypted !");
        Console.ReadKey();
    }
}
catch (Exception ex)
{
    Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
sandi nglindhungi file excel

Enkripsi pratinjau file Excel.

Saiki ayo ngembangake pemahaman babagan potongan kode:

CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

Nggawe obyek CellsApi nalika menehi kredensial klien minangka argumen.

var file = System.IO.File.OpenRead(input_ODS);

Waca isi input Excel saka drive sistem lokal.

cellsInstance.UploadFile(input_Excel, File.OpenRead(input_Excel));

Unggah input Excel menyang panyimpenan maya.

WorkbookEncryptionRequest encryption = new WorkbookEncryptionRequest();
encryption.Password = "123456";
encryption.KeyLength = 128;
encryption.EncryptionType = "XOR";

Nggawe panjalukan enkripsi Workbook ing ngendi kita nemtokake XOR minangka jinis enkripsi.

var response = cellsInstance.CellsWorkbookPostEncryptDocument(input_Excel, encryption, null);

Pungkasan, nelpon cara iki kanggo nglindhungi sandhi file Excel. File sing dienkripsi bakal disimpen ing panyimpenan awan.

File Excel conto sing digunakake ing conto ing ndhuwur bisa diundhuh saka myDocument.xlsx.

Tambah Sandi menyang Excel nggunakake perintah cURL

cURL minangka alat baris perintah sing ngidini sampeyan nransfer data menyang lan saka server nggunakake macem-macem protokol, kalebu HTTP, HTTPS, FTP, lan liya-liyane. Prentah cURL uga bisa migunani kanggo tujuan skrip lan otomatisasi. Iki bisa migunani banget yen sampeyan duwe akeh file Excel sing kudu dienkripsi, utawa yen sampeyan kudu nindakake operasi iki kanthi rutin. Mulane, tinimbang nindakake operasi kasebut kanthi manual nggunakake browser web utawa antarmuka pangguna grafis, sampeyan bisa nggunakake printah cURL kanggo sesambungan karo Aspose.Cells Cloud API langsung saka baris printah.

Kanggo miwiti, sampeyan kudu nginstal cURL ing sistem sampeyan banjur ngasilake accessToken adhedhasar kredensial klien:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Gunakake printah ing ngisor iki kanggo ngunggah input Excel menyang panyimpenan maya:

curl -v "https://api.aspose.cloud/v3.0/cells/storage/file/{filePath}" \
-X PUT \
-F file=@{localFilePath} \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer {accessToken}"

Ganti {filePath} karo path sing arep disimpen file ing panyimpenan maya, {localFilePath} karo path file Excel ing sistem lokal, lan {accessToken} karo Aspose Cloud akses token.

Pungkasan, tindakake printah ing ngisor iki kanggo nglindhungi file Excel kanthi sandhi:

curl -v "https://api.aspose.cloud/v3.0/cells/{excelName}]/encryption" \
-X POST \
-H  "accept: application/json" \
-H  "authorization: Bearer {accessToken}" \
-H  "Content-Type: application/json" \
-d "{  \"EncryptionType\": \"XOR\",  \"KeyLength\": 128,  \"Password\": \"123456\"}"

Ganti {excelName} karo jeneng berkas Excel sing diunggah menyang panyimpenan maya, lan {accessToken} nganggo token akses sing digawe ing ndhuwur. Sawise eksekusi, asil Excel bakal disimpen ing panyimpenan maya sing padha.

Panutup

Kita wis sinau manawa Aspose.Cells Cloud SDK kanggo .NET nyedhiyakake cara sing gampang lan aman kanggo nglindhungi sandhi lan ndhelik file Excel nggunakake perintah cURL lan metode API. Sakabèhé, Aspose.Cells Cloud SDK kanggo .NET minangka alat sing apik kanggo pangembang sing kudu ngetrapake langkah-langkah keamanan kanggo file Excel. Kanthi nggunakake API iki, pangembang bisa mesthekake yen informasi sensitif lan rahasia sing disimpen ing file Excel direksa saka akses ora sah, lan tundhuk karo syarat peraturan. Pungkasan, API wis kabukten minangka alat sing migunani kanggo ngrampungake kabutuhan proteksi sandhi lan enkripsi file Excel.

Pranala Migunani

Artikel sing Disaranake

Mangga bukak link ing ngisor iki kanggo mangerteni sing luwih lengkap babagan: