हिन्दी

अपने लाइसेंस फ़ाइल की सुरक्षा

आपका लाइसेंस उन अनुप्रयोगों में शामिल होता है जो आप बनाते हैं। इससे एक संभावित सुरक्षा जोखिम उत्पन्न होता है—कोई व्यक्ति लाइसेंस खोज कर उसे कॉपी या लीक कर सकता है। लाइसेंस को एक आंतरिक संसाधन के रूप में एम्बेड करने से कुछ हद तक सुरक्षा मिलती है, लेकिन मूल फ़ाइल अभी भी डिप्लॉयमेंट पैकेज से प्राप्त की जा सकती है। यह पृष्ठ एन्क्रिप्शन का उपयोग करके आपकी लाइसेंस फ़ाइल को अधिक सुरक्षित रूप से संरक्षित करने के लिए कोड प्रदान करता है। कृपया नीचे दिए गए उदाहरणों में से एक चुनें:

C#

public void EncryptDecryptLicense()
{
    string encryptedFilePath = MyDir + "EncryptedLicense.txt";

    // Load the contents of the license into a byte array.
    byte[] licBytes = File.ReadAllBytes("YourLicense.lic");
    // Use this key only once for this license file.
    // To protect another file first generate a new key.
    byte[] key = GenerateKey(licBytes.Length);

    // Write the encrypted license to disk.
    File.WriteAllBytes(encryptedFilePath, EncryptDecryptLicense(licBytes, key));

    // Load the encrypted license and decrypt it using the key.
    byte[] decryptedLicense;
    decryptedLicense = EncryptDecryptLicense(File.ReadAllBytes(encryptedFilePath), key);

    // Load the decrypted license into a stream and set the license.
    MemoryStream licenseStream = new MemoryStream(decryptedLicense);

    License license = new License();
    license.SetLicense(licenseStream);
}

/// <summary>
/// A method used for encrypting and decrypting data using XOR.
/// </summary>
public byte[] EncryptDecryptLicense(byte[] licBytes, byte[] key)
{
    byte[] output = new byte[licBytes.Length];

    for (int i = 0; i < licBytes.Length; i++)
        output[i] = Convert.ToByte(licBytes[i] ^ key[i]);

    return output;
}

/// <summary>
/// Generates a random key the same length as the license (a one time pad).
/// </summary>
public byte[] GenerateKey(long size)
{
    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    byte[] strongBytes = new Byte[size];
    rng.GetBytes(strongBytes);

    return strongBytes;
}

 

Java

public void encryptDecryptLicense() throws Exception
{
    String encryptedFilePath = getMyDir + "EncryptedLicense.txt";

    // Load the contents of the license into a byte array.
    byte[] licBytes = readAllBytesFromFile("YourLicense.lic");
    // Use this key only once for this license file.
    //To protect another file first generate a new key.
    byte[] key = generateKey(licBytes.Length);

    // Write the encrypted license to disk.
    BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(
                                           encryptedFilePath));
    output.write(encryptDecryptLicese(licBytes, key));
    output.close();
    
    // Load the encrypted license and decrypt it using the key.
    byte[] decryptedLicense = encryptDecryptLicense(
                      readAllBytesFromFile(encryptedFilePath), key);

    // Load the decrypted license into a stream and set the license.
    ByteArrayInputStream licenseStream = new ByteArrayInputStream(decryptedLicense);

    License license = new License();
    license.SetLicense(licenseStream);
}

// A method used for encrypting and decrypting data using XOR.
public byte[] encryptDecryptLicense(byte[] licBytes, byte[] key)
{
    byte[] output = new byte[licBytes.Length];

    for (int i = 0; i < licBytes.Length; i++)
        output[i] = (byte)(licBytes[i] ^ key[i]);

    return output;
}

// Generates a random key the same length as the license (a one time pad).
public byte[] generateKey(int size)
{
    SecureRandom rng = new SecureRandom();
    byte[] strongBytes = new byte[size];
    rng.nextBytes(strongBytes);

    return strongBytes;
}

public byte[] readAllBytesFromFile(String filePath) Throws IOException
{
    int pos;
    InputStream inputStream = new FileInputStream(filePath);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    while ((pos = inputStream.Read() != -1)
        bos.write(pos);
        
    inputStream.close();
                    
    return bos.toByteArray();
}
 
Aspose logo
प्रश्न?

यदि आपके कोई प्रश्न या समस्याएँ हैं, तो कृपया हमारे सेल्स सपोर्ट से संपर्क करें जो आपकी सहायता करने में खुशी महसूस करेंगे!