PDF ana amfani da fayiloli sosai don adanawa da raba mahimman bayanai, daga bayanan kuɗi zuwa takaddun doka. Koyaya, waɗannan fayilolin na iya zama masu rauni ga samun izini da gyara ba tare da izini ba, wanda shine dalilin da yasa ɓoyewa da kare kalmar sirri PDFs yana da mahimmanci don kiyaye amincin su. A cikin wannan gidan yanar gizon, za mu bincika yadda ake ɓoyewa da kuma kalmar sirri-kare fayilolin PDF ta amfani da APIs na tushen Python. Ta bin umarnin mataki-mataki da aka zayyana a cikin wannan jagorar, za ku sami damar ƙara ƙarin tsaro a fayilolin PDF ɗinku kuma tabbatar da cewa sun kasance cikin aminci daga idanu masu zazzagewa. Don haka ko kuna buƙatar kare takaddun kasuwanci na sirri ko fayilolin sirri, karanta don koyon yadda ake ɓoyewa, karewa, da amintar fayilolin PDF ɗinku cikin sauƙi.
API ɗin REST don Kare PDF
Aspose.PDF Cloud SDK don Python kayan aiki ne mai ƙarfi wanda ke ba ku damar ƙara kariyar kalmar sirri zuwa fayilolin PDF ɗinku cikin sauƙi. Tare da ƴan layukan lamba kawai, zaku iya ɓoye fayilolin PDF ɗinku kuma ku hana samun dama ga mutane masu izini. SDK yana ba da algorithms ɓoye da yawa don zaɓar daga, gami da 40-bit RC4, 128-bit RC4, 128-bit AES, da 256-bit AES.
Yanzu, don farawa da Python SDK, matakin farko shine shigarwa. Akwai don saukewa akan PIP da GitHub ma’ajiyar. Don haka da fatan za a aiwatar da umarni mai zuwa akan tasha / umarni da sauri don shigar da sabuwar sigar SDK akan tsarin.
pip install asposepdfcloud
Shaidar Abokin Ciniki
Bayan shigarwa, babban mataki na gaba shine biyan kuɗi kyauta ga ayyukan girgijenmu akan Aspose.Cloud dashboard. Kawai Yi rijista ta amfani da GitHub ko asusun Google ta danna maɓallin Ƙirƙiri sabon Asusu kuma samar da bayanan da ake buƙata. Sannan shiga tare da sabon asusun da aka yi rajista kuma ku sami Shaidar Abokin Cinikinku.
Encrypt PDF ta amfani da Python
API ɗin yana ba ku damar saita nau’ikan kalmomin shiga guda biyu wato Buɗe kalmar sirri (Password mai amfani) da kalmar wucewar Izinin (masirar sirri).
Rubutun buɗe kalmar sirri
Bude kalmar sirri na Takarda (wanda kuma aka sani da kalmar sirrin mai amfani) yana buƙatar mai amfani ya rubuta kalmar sirri don buɗe PDF.
Kalmar sirrin izini
Ana buƙatar kalmar sirri ta izini (kuma aka sani da kalmar sirri/mallaki) don canza saitunan izini. Yin amfani da kalmar sirri ta izini, zaku iya ƙuntata bugu, gyara, da kwafin abun ciki a cikin PDF. Ana buƙatar wannan kalmar sirri don canza ƙuntatawa da kuka riga kuka yi amfani da su.
Idan PDF ɗin yana da alaƙa da nau’ikan kalmomin shiga guda biyu, ana iya buɗe shi da kowane kalmar sirri.
Hakanan, da fatan za a lura cewa API ɗin yana karɓar mai shi da kalmomin shiga na mai amfani a cikin tsarin Base64. A cikin snippet na lamba mai zuwa, an ƙayyade kalmar sirrin mai shi (b3duZXJcLy8/ICQxMl5QYXNzd29yZCEm) da kalmar sirrin mai amfani (dXNlciAkXlBhc3N3b3JkISY=). Da fatan za a bi matakan da aka bayar a ƙasa don ɓoye fayilolin PDF ta amfani da snippet code na Python.
- Ƙirƙiri misali na aji ApiClient yayin samar da ID na Abokin ciniki & Sirrin Abokin ciniki azaman muhawara
- Na biyu, ƙirƙiri misali na ajin PdfApi wanda ke ɗaukar abu ApiClient azaman hujjar shigarwa
- Yanzu kira hanyar postencryptdocumentinstorage(..) hanyar PdfApi yayin ƙaddamar da sunan shigar da fayil ɗin PDF, mai amfani da kalmomin shiga (a cikin Base64 encoding) da algorithm na Cryptographic azaman muhawara.
Shi ke nan! Tare da ƴan layukan lambar, mun koyi matakan kalmar sirri-kare fayilolin PDF ta amfani da Aspose.PDF Cloud SDK don Python.
def encrypt():
try:
#Client credentials
client_secret = "d34641f4ff6bcc96e3a0ab6ac69768b2"
client_id = "8e2b082f-1f74-4bc0-b454-5f68457d1c97"
#initialize PdfApi client instance using client credetials
pdf_api_client = asposepdfcloud.api_client.ApiClient(client_secret, client_id)
# ƙirƙirar misalin PdfApi yayin wucewa PdfApiClient azaman hujja
pdf_api = PdfApi(pdf_api_client)
#input PDF file name
input_file = 'image-based-pdf-sample.pdf'
# kira API don ɓoye daftarin aiki
response = pdf_api.post_encrypt_document_in_storage(name=input_file,user_password='dXNlciAkXlBhc3N3b3JkISY=',owner_password='b3duZXJcLy8/ICQxMl5QYXNzd29yZCEm',crypto_algorithm='AESX128')
# buga sakon nasara a cikin na'ura mai kwakwalwa (na zaɓi)
print('PDF encrypted successfully !')
except ApiException as e:
print("Exception while calling PdfApi: {0}".format(e))
print("Code:" + str(e.code))
print("Message:" + e.message)
Lura cewa zaku iya amfani da ɗayan ƙimar algorithm ɗin cryptographic yayin aiwatar da ɓoyayyen PDF
Suna | Bayani |
---|---|
RC4x40 | RC4 tare da tsayin maɓalli 40. |
RC4x128 | RC4 tare da tsayin maɓalli 128. |
AESx128 | AES tare da tsayin maɓalli 128. |
AESx256 | AES tare da tsayin maɓalli 256. |
Za a iya sauke fayil ɗin shigarwar PDF da aka yi amfani da shi a cikin misalin da ke sama daga awesomeTable.pdf.
Rufe PDF ta amfani da Umurnin CURL
Hakanan ana samun damar API ɗin REST ta umarnin cURL akan kowane dandamali. Za mu iya yin amfani da taga mai sauri/tasha don aiwatar da umarnin CURL. Tun da Aspose.PDF Cloud kuma an haɓaka shi kamar yadda tsarin gine-gine na REST, don haka za mu iya amfani da umarnin cURL don ɓoye fayilolin PDF. Amma kafin ci gaba da gaba, muna buƙatar samar da JSON Web Token (JWT) bisa ga daidaitattun shaidar abokin ciniki da aka ƙayyade akan dashboard na Aspose.Cloud. Ya zama wajibi saboda APIs ɗin mu suna samun isa ga masu amfani da rajista kawai. Da fatan za a aiwatar da umarni mai zuwa don samar da alamar JWT.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Yanzu, da zarar muna da alamar JWT, muna buƙatar aiwatar da umarni mai zuwa don ɓoye takaddar PDF.
curl -v -X POST "https://api.aspose.cloud/v3.0/pdf/awesomeTable.pdf/encrypt?userPassword=dXNlciAkXlBhc3N3b3JkISY%3D&ownerPassword=b3duZXJcLy8%2FICQxMl5QYXNzd29yZCEm&cryptoAlgorithm=AESx128&permissionsFlags=AssembleDocument&usePdf20=false" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Kammalawa
A ƙarshe, yin amfani da API na REST don ɓoye fayilolin PDF hanya ce mai sauri da inganci don tabbatar da tsaro da sirrin muhimman takaddun ku. Ko kuna buƙatar kulle PDF daga gyara ko ƙara kariyar kalmar sirri, waɗannan hanyoyin suna ba da mafita mai dacewa wanda ke da aminci da aminci. Ta bin matakan da aka zayyana a cikin wannan gidan yanar gizon, zaku iya amintar da fayilolin PDF ɗinku cikin sauƙi kuma ku tabbata cewa an kiyaye mahimman bayanan ku.
Lura cewa girgijen SDK ɗin mu an gina su a ƙarƙashin lasisin MIT, saboda haka zaku iya zazzage cikakken snippet lambar daga GitHub. Bugu da ƙari, muna ba da shawarar sosai bincika Jagorancin Mai Haɓakawa don ƙarin koyo game da wasu abubuwan ban sha’awa na API.
A ƙarshe, idan kun ci karo da kowace matsala ko kuna da wata tambaya mai alaƙa yayin amfani da API, da fatan za ku ji daɗin tuntuɓar mu ta [ dandalin tallafin abokin ciniki kyauta 18.
Labarai masu alaka
Muna kuma ba da shawarar yin bibiyar labarai na gaba don ƙarin koyo game da su