حماية العروض التقديمية بكلمة مرور في JavaScript

نظرة عامة

كلمة المرور الافتتاحية تقوم بتشفير العرض التقديمي. يُتطلب كلمة المرور الصحيحة لتحميل وعرض محتوى العرض التقديمي، وبالتالي توفر هذه الحماية السرية.

كلمة المرور الافتتاحية تختلف عن كلمة مرور الحماية من الكتابة. الحماية من الكتابة تقيّد التعديل لكنها لا تشفر المحتوى ولا تمنع تحميل العرض التقديمي. لإدارة كلمات المرور لتعديل العروض التقديمية، راجع Write-Protect Presentations.

تطبق سير العمل أدناه على كل من عروض PPT و PPTX. تستخدم الأمثلة كلا الصيغتين حيث يكون سلوكهما القائم على الملفات أو التدفقات مهمًا.

تشفير عرض تقديمي بكلمة مرور افتتاحية

استخدم ProtectionManager.encrypt لتعيين كلمة مرور افتتاحية. ثم استخدم Presentation.save لحفظ العرض التقديمي المشفر.

المثال التالي يشفر عرض PPTX:

const slides = require("aspose.slides.via.java");

const presentation = new slides.Presentation("pres.pptx");
try {
    presentation.getProtectionManager().encrypt("open_password");
    presentation.save("encrypted-pres.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

اجعل خصائص المستند عامة

بشكل افتراضي، تتضمن Aspose.Slides خصائص المستند في تشفير العرض التقديمي. تتحكم الطريقة ProtectionManager.setEncryptDocumentProperties في هذا السلوك بشكل مستقل عن تشفير محتوى الشرائح. مرّر false قبل استدعاء ProtectionManager.encrypt عندما يتعين على نظام الفهرسة أو التصنيف أو البحث أو إدارة الوثائق قراءة البيانات الوصفية دون كلمة المرور الافتتاحية.

المثال التالي ينشئ عرض PPTX مشفر مع ترك خصائص المستند المدمجة عامة:

const slides = require("aspose.slides.via.java");

const presentation = new slides.Presentation();
try {
    const properties = presentation.getDocumentProperties();
    properties.setAuthor("Contoso Knowledge Management");
    properties.setTitle("Quarterly Product Roadmap");
    properties.setKeywords("roadmap, planning, internal");

    presentation.getSlides().get_Item(0).setName("Encrypted presentation content");
    presentation.getProtectionManager().setEncryptDocumentProperties(false);
    presentation.getProtectionManager().encrypt("open_password");
    presentation.save("public-properties-encrypted.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

تمرير false إلى ProtectionManager.setEncryptDocumentProperties لا يجعل الشرائح أو القوالب أو التخطيطات أو الأشكال أو الوسائط أو غيرها من محتوى العرض التقديمي عامة. يؤثر فقط على خصائص المستند. لقراءة تلك الخصائص دون تحميل المحتوى المشفر، راجع Manage Presentation Properties.

تحميل عرض تشفير

عيّن LoadOptions.setPassword إلى كلمة المرور الافتتاحية ومرّر الخيارات إلى Presentation عند تحميل الملف. سيظهر فشل في التحميل عندما تكون كلمة المرور الافتتاحية مطلوبة ولكن كلمة المرور المقدمة مفقودة أو غير صحيحة.

const slides = require("aspose.slides.via.java");

const loadOptions = new slides.LoadOptions();
loadOptions.setPassword("open_password");

const presentation = new slides.Presentation("encrypted-pres.pptx", loadOptions);
try {
    // العمل مع العرض التقديمي المفكّ تشفيره.
} finally {
    presentation.dispose();
}

إزالة التشفير من عرض تقديمي

حمّل العرض التقديمي باستخدام كلمة المرور الافتتاحية، استدعِ ProtectionManager.removeEncryption، واحفظ النتيجة. يمكن بعد ذلك تحميل العرض التقديمي المحفوظ دون كلمة مرور.

const slides = require("aspose.slides.via.java");

const loadOptions = new slides.LoadOptions();
loadOptions.setPassword("open_password");

const presentation = new slides.Presentation("encrypted-pres.pptx", loadOptions);
try {
    presentation.getProtectionManager().removeEncryption();
    presentation.save("encryption-removed.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

التحقق من كلمة المرور الافتتاحية قبل التحميل

استخدم PresentationFactory.getPresentationInfo للحصول على PresentationInfo دون إنشاء نسخة كاملة من العرض التقديمي. افحص PresentationInfo.isPasswordProtected قبل طلب أو التحقق من كلمة مرور. عندما تكون الحماية موجودة، تحقق من القيمة التي تم التحقق منها باستخدام PresentationInfo.checkPassword.

سير عمل المسار إلى الملف

المثال التالي يتحقق من كلمة مرور افتتاحية لملف PPTX، يمرّر القيمة التي تم التحقق منها إلى LoadOptions.setPassword، ثم يحمل العرض التقديمي الكامل:

const slides = require("aspose.slides.via.java");

const filePath = "protected-presentation.pptx";
const password = "open_password";
const presentationInfo = slides.PresentationFactory.getInstance().getPresentationInfo(filePath);

if (!presentationInfo.isPasswordProtected()) {
    console.log("The presentation does not have an opening password.");
} else if (!presentationInfo.checkPassword(password)) {
    console.log("The opening password is incorrect.");
} else {
    const loadOptions = new slides.LoadOptions();
    loadOptions.setPassword(password);

    const presentation = new slides.Presentation(filePath, loadOptions);
    try {
        console.log("The presentation was validated and loaded successfully.");
    } finally {
        presentation.dispose();
    }
}

سير عمل التدفق

استخدم PresentationFactory.getPresentationInfoFromStream لفحص تدفق قابل للقراءة في Node.js. بعد استهلاك تدفق الفحص، أنشئ تدفقًا جديدًا قبل تحميل العرض التقديمي الكامل باستخدام Presentation.createPresentationFromStream.

المثال التالي يستخدم ملف PPT:

const slides = require("aspose.slides.via.java");
const fs = require("fs");

const filePath = "protected-presentation.ppt";
const password = "open_password";
const presentationFactory = slides.PresentationFactory.getInstance();
const infoStream = fs.createReadStream(filePath);

slides.PresentationFactory.getPresentationInfoFromStream(presentationFactory, infoStream, function(infoError, presentationInfo) {
    if (infoError) {
        console.log("The presentation information could not be read: " + infoError.message);
    } else if (!presentationInfo.isPasswordProtected()) {
        console.log("The presentation does not have an opening password.");
    } else if (!presentationInfo.checkPassword(password)) {
        console.log("The opening password is incorrect.");
    } else {
        const loadOptions = new slides.LoadOptions();
        loadOptions.setPassword(password);
        const presentationStream = fs.createReadStream(filePath);

        slides.Presentation.createPresentationFromStream(presentationStream, loadOptions, function(loadError, presentation) {
            if (loadError) {
                console.log("The presentation could not be loaded: " + loadError.message);
            } else {
                try {
                    console.log("The presentation was validated and loaded successfully.");
                } finally {
                    presentation.dispose();
                }
            }
        });
    }
});

قيم الإرجاع لدالة checkPassword

PresentationInfo.checkPassword تُعيد true فقط عندما يكون للعرض التقديمي كلمة مرور افتتاحية وكانت كلمة المرور المقدمة صحيحة. تُعيد false في كل من الحالات التالية:

  • كلمة المرور غير صحيحة.
  • العرض التقديمي لا يحتوي على كلمة مرور افتتاحية.
  • الكلمة المقدمة هي null أو فارغة.

السلوك نفسه ينطبق على عروض PPT و PPTX.

التحقق مما إذا كان العرض التقديمي المحمّل مشفرًا

بعد تحميل عرض تقديمي باستخدام كلمة المرور الصحيحة، افحص ProtectionManager.isEncrypted للتأكد من أن العرض الأصلي كان مشفرًا. لاكتشاف حماية كلمة المرور الافتتاحية قبل التحميل، استخدم PresentationInfo.isPasswordProtected كما هو موضح أعلاه.

const slides = require("aspose.slides.via.java");

const loadOptions = new slides.LoadOptions();
loadOptions.setPassword("open_password");

const presentation = new slides.Presentation("encrypted-pres.pptx", loadOptions);
try {
    const isEncrypted = presentation.getProtectionManager().isEncrypted();
    console.log("The presentation is encrypted: " + isEncrypted);
} finally {
    presentation.dispose();
}

توصيات الأمان

حماية عرض تقديمي بكلمة مرور عبر الإنترنت

  1. افتح تطبيق Aspose.Slides Lock.
  2. حدد أو حمّل العرض التقديمي.
  3. أدخل كلمة مرور لحماية العرض.
  4. اختياريًا، أدخل كلمة مرور منفصلة لحماية التعديل.
  5. طبق الحماية وحمّل الملف الناتج.

الأسئلة المتكررة

ما الفرق بين كلمة المرور الافتتاحية وكلمة مرور الحماية من الكتابة؟

كلمة المرور الافتتاحية تشفر العرض التقديمي وتكون مطلوبة لتحميل محتواه. كلمة مرور الحماية من الكتابة تقيّد التعديل دون تشفير المحتوى.

هل يمكنني التحقق من كلمة المرور الافتتاحية دون تحميل جميع الشرائح؟

نعم. احصل على معلومات العرض التقديمي، وتحقق ما إذا كانت حماية كلمة المرور الافتتاحية موجودة، وحقق من صحة كلمة المرور قبل إنشاء نسخة كاملة من العرض التقديمي.

هل يمكن للتطبيق قراءة البيانات الوصفية دون كلمة المرور الافتتاحية؟

نعم، ولكن فقط عندما يكون العرض التقديمي مشفرًا مع تعطيل تشفير خصائص المستند. يجب على التطبيق حينئذٍ استخدام وضع التحميل الذي يقتصر على خصائص المستند كما هو موضح في Manage Presentation Properties.

هل تدعم سير عمل فحص كلمة المرور كلًا من PPT و PPTX؟

نعم. اكتشاف كلمة المرور والتحقق منها عبر مسار الملف أو التدفق يعملان بنفس الطريقة بالنسبة لعروض PPT و PPTX.