com.alachisoft.ncache.ncactivate.license.NCCrypto Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-activate Show documentation
Show all versions of nc-activate Show documentation
internal package of Alachisoft.
package com.alachisoft.ncache.ncactivate.license;
import com.alachisoft.ncache.ncactivate.utils.StringRef;
import java.util.Date;
import java.util.Random;
/*
* NCCrypto.java
*
* Created on September 28, 2006, 10:37 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
* @author Administrator
*/
public class NCCrypto {
/**
* Creates a new instance of NCCrypto
*/
public NCCrypto() {
}
static void Scramble(ByteRef dataPtr, int dwSize, int offset) {
Date dte = new Date();
Random rnd = new Random(dte.getTime());
for (int i = 0, j = offset; i < dwSize; i++, j++) {
dataPtr.data[j] = (byte) rnd.nextInt();
}
}
public static void Scramble(byte[] dataPtr, int dwSize) {
Date dte = new Date();
Random rnd = new Random(dte.getTime());
for (int i = 0; i < dwSize; i++) {
dataPtr[i] = (byte) rnd.nextInt();
}
}
// Simple XOR-based symmetric encryption/decryption function.
public static void EncryptDecryptBytes(ByteRef pBytes, long nCount, int nOffset) {
char xorVal = (char) 141;
for (int i = 0, j = nOffset; i < nCount; i++, j++) {
xorVal = (char) (((xorVal << (i % 1)) ^ (i * i * 17)) % 256);
pBytes.data[j] ^= xorVal;
}
}
public static String EDecode(StringRef ptr) {
int dlen = ebase64.decode(ptr, null) + 1;
char[] dBuf = new char[dlen];
StringRef dBuf2 = new StringRef();
dBuf2.strData = new String(dBuf);
ebase64.decode(ptr, dBuf2);
String res = dBuf2.strData;
return res;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy