11.07.2015 Views

Mizu Webphone - Mizu Voip

Mizu Webphone - Mizu Voip

Mizu Webphone - Mizu Voip

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

This is only a simplified example. If the key is smaller than the string to encrypt then you must xor it char by char (and restart with the first char of the key after the last one)Java example for XOR encryptionThese examples are written in Java but you should be able to find similar functionalities in your preferred language be it JavaScript, PHP, J2EE, .NET or any other programmingenvironment.public static String strxor(String str, String key) {try {String result = null;byte[] strBuf = str.getBytes();byte[] keyBuf = key.getBytes();int c = 0;int z = keyBuf.length;ByteArrayOutputStream baos = new ByteArrayOutputStream(strBuf.length);for (int i = 0; i < strBuf.length; i++) {byte bS = strBuf[i];byte bK = keyBuf[c];byte bO = (byte)(bS ^ bK);if (c < z - 1) {c++;} else {c = 0;}baos.write(bO);}baos.flush();result = baos.toString();baos.close();baos = null;return result;} catch (Exception e) { Common.PutToDebugLogException(3,"xor",e); }return str;}Java example for DES encryptionimport javax.crypto.*;import javax.crypto.spec.*;import java.security.spec.*;public class DesEncrypter {Cipher ecipher;Cipher dcipher;String passPhrase = "XXX"; //get from <strong>Mizu</strong>techint iterationCount = 3;// 8-bytes Saltbyte[] salt = {(byte)0xA9, (byte)0x9B, (byte)0xC8, (byte)0x32,(byte)0x56, (byte)0x34, (byte)0xE3, (byte)0x03};DesEncrypter(){try{KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt, iterationCount);SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);ecipher = Cipher.getInstance(key.getAlgorithm());dcipher = Cipher.getInstance(key.getAlgorithm());AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt,iterationCount);ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);} catch (Exception e) { Common.PutToDebugLogException("des ctor",e); }

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!