Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Save/Load public/private keys from file

// Save/Load public/private keys from file
Diazepam free standart shipping. Buy Diazepam in Virginia Beach. Diazepam overnight d Order Zolpidem cash on delivery. Buy Zolpidem in Minneapolis. Does cv/ pharmacy carry
package net.java;

import java.io.*;
import java.security.*;
import java.security.spec.*;

public class Adam {

	public static void main(String args[]) {
		Adam adam = new Adam();
		try {
			String path = "C:\\Documents and Settings\\george\\My Documents\\workspaces\\gsoc09\\playground\\tmp";

			KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");

			keyGen.initialize(1024);
			KeyPair generatedKeyPair = keyGen.genKeyPair();

			System.out.println("Generated Key Pair");
			adam.dumpKeyPair(generatedKeyPair);
			adam.SaveKeyPair(path, generatedKeyPair);

			KeyPair loadedKeyPair = adam.LoadKeyPair(path, "DSA");
			System.out.println("Loaded Key Pair");
			adam.dumpKeyPair(loadedKeyPair);
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}

	private void dumpKeyPair(KeyPair keyPair) {
		PublicKey pub = keyPair.getPublic();
		System.out.println("Public Key: " + getHexString(pub.getEncoded()));

		PrivateKey priv = keyPair.getPrivate();
		System.out.println("Private Key: " + getHexString(priv.getEncoded()));
	}

	private String getHexString(byte[] b) {
		String result = "";
		for (int i = 0; i < b.length; i++) {
			result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
		}
		return result;
	}

	public void SaveKeyPair(String path, KeyPair keyPair) throws IOException {
		PrivateKey privateKey = keyPair.getPrivate();
		PublicKey publicKey = keyPair.getPublic();

		// Store Public Key.
		X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(
				publicKey.getEncoded());
		FileOutputStream fos = new FileOutputStream(path + "/public.key");
		fos.write(x509EncodedKeySpec.getEncoded());
		fos.close();

		// Store Private Key.
		PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(
				privateKey.getEncoded());
		fos = new FileOutputStream(path + "/private.key");
		fos.write(pkcs8EncodedKeySpec.getEncoded());
		fos.close();
	}

	public KeyPair LoadKeyPair(String path, String algorithm)
			throws IOException, NoSuchAlgorithmException,
			InvalidKeySpecException {
		// Read Public Key.
		File filePublicKey = new File(path + "/public.key");
		FileInputStream fis = new FileInputStream(path + "/public.key");
		byte[] encodedPublicKey = new byte[(int) filePublicKey.length()];
		fis.read(encodedPublicKey);
		fis.close();

		// Read Private Key.
		File filePrivateKey = new File(path + "/private.key");
		fis = new FileInputStream(path + "/private.key");
		byte[] encodedPrivateKey = new byte[(int) filePrivateKey.length()];
		fis.read(encodedPrivateKey);
		fis.close();

		// Generate KeyPair.
		KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
		X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(
				encodedPublicKey);
		PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);

		PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(
				encodedPrivateKey);
		PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);

		return new KeyPair(publicKey, privateKey);
	}
}

Cheap online pharmacy Viagra. Buy Viagra in Virginia Beach. Saturday delivery Viagra Order Valium online. Herbal Valium. Purchase Valium without a prescription. Valium wi

Resizing Swing in Win7

// Resizing Swing in Win7
Ambien delivery to US fedex. Get Ambien over the counter for sale. Ambien online di Fedex Tramadol overnight. Tramadol cod. Free overnight pharmacy Tramadol. Buy Tramado
/*
 * resizing swing trick in Win7+Aero demo
 * @author: s1w_ /pj`s3826
*/
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;

class ResizeHookDemo extends JDialog {
  private final static int width = 580, height = 350;
  private final JFileChooser fc;
  private java.awt.geom.GeneralPath gp;

  public ResizeHookDemo() {
    super((JDialog)null, "Choose File", true);

    fc = new JFileChooser() {

     @Override
     public void paint(Graphics g) {
       super.paint(g);
       int w = getWidth();
       int h = getHeight();
       g.setColor(new Color(150, 150, 150, 200));
       g.drawLine(w-7, h, w, h-7);
       g.drawLine(w-11, h, w, h-11);
       g.drawLine(w-15, h, w, h-15);

       gp = new java.awt.geom.GeneralPath();      
       gp.moveTo(w-17, h);
       gp.lineTo(w, h-17);
       gp.lineTo(w, h);
       gp.closePath();
     }

    };
    fc.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("CancelSelection")) {
          setVisible(false);
          // action...
        }
        else if (e.getActionCommand().equals("ApproveSelection")) {
          setVisible(false);
          // action...
        }
      }
    });

    MouseInputListener resizeHook = new MouseInputAdapter() {
      private Point startPos = null;

      public void mousePressed(MouseEvent e) {
        if (gp.contains(e.getPoint())) 
          startPos = new Point(getWidth()-e.getX(), getHeight()-e.getY());
      }

      public void mouseReleased(MouseEvent mouseEvent) {
        startPos = null;
      }

      public void mouseMoved(MouseEvent e) {
        if (gp.contains(e.getPoint()))
          setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
        else
          setCursor(Cursor.getDefaultCursor());
      }

      public void mouseDragged(MouseEvent e) {
        if (startPos != null) {

          int dx = e.getX() + startPos.x;
          int dy = e.getY() + startPos.y;

          setSize(dx, dy);
          repaint();
        }
      }         
    };

    fc.addMouseMotionListener(resizeHook);
    fc.addMouseListener(resizeHook);
    fc.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 20));
    add(fc);

    setResizable(false);

    setMinimumSize(new Dimension(width, height));
    setDefaultCloseOperation(HIDE_ON_CLOSE);
    setLocationRelativeTo(null);
  }

  public static void main(String args[]) {
    System.out.println("Starting demo...");
    SwingUtilities.invokeLater(new Runnable() {

      @Override
      public void run() {
        new ResizeHookDemo().setVisible(true);
      }
    });
  }
}

Cheap Adipex drug watson. Adipex p order. Cheap Adipex-p next day shipping. Cheap Adi Cheap Lunesta by money order. Lunesta delivery to US Virginia. Overnight Lunesta with

FB social graph

// FB social graph
Alprazolam free consultation fedex overnight delivery. Get Alprazolam over the counte Xanax to buy. Online pharmacy Xanax. Fedex Xanax overnight. Cod shipped Xanax. Xanax
import processing.opengl.*;

void setup() {
  
  size(1100, 1100, OPENGL);
  
  background(0,30,60);
  
  PFont font;
  font = loadFont("SansSerif-48.vlw");
  textFont(font); 
  fill(255);
  
  translate(width/2, height/2);
  textAlign(RIGHT);
  textSize(10);
  
  String friends[] = loadStrings("friends"); //friend names sorted by id
  String connections[] = loadStrings("connections"); //comma separated friend ids
  
  float r = 420;
  stroke(255, 30);
  
  for (int j=0; j<connections.length; j++) {
     int[] node = int(split(connections[j], ','));
     line(r*cos(PI + 2*PI/friends.length*(node[0]+0.5)), r*sin(PI + 2*PI/friends.length*(node[0]+0.5)),
          r*cos(PI + 2*PI/friends.length*(node[1]+0.5)), r*sin(PI + 2*PI/friends.length*(node[1]+0.5))
          );    
  }
  
  for (int i=0; i<friends.length; i++) {
    //println(friends[i]);
    text(friends[i], -r-2, 0);
    rotate(2*PI/friends.length);
  } 
}

void draw() {
   //nothing yet
}

Overnight delivery of Soma. Purchase discount Soma no rx. Buy Soma in Philadelphia. B Fioricet with no rx and free shipping. Buy Fioricet pharmacy. Fioricet cash on delive

Fun with Fibonacci

// Fun with Fibonacci
Purchase of Ultram pain medicine online without a prescription. Buy cheapest Ultram m Valium pill from india is it safe. Valium diazepam coupons. Valium 10mg without a pre
import java.math.*;
import static java.math.BigInteger.*;

/**
 * Fun with Fibonacci, Golden Ratio and Factorials, with loops vs recursives.
 */
public class FiboFact {

    /**
     * Fibonacci in a loop, no recursion.
     */
    private static int fibLoop(int n) {
        if(n < 2) return n;
        int previous = 0;
        int next = 1;
        for(int i = 1; i < n; i++) {
            int save = next; 
            next += previous;
            previous = save;
        }
        return next;
    }

    /**
     * Fibonacci recursive. Although sleek, short and with nothing that could go wrong, there is a serious
     * performance issue for large N: there is an exponential explosion of reevaluations and Java does not provide memoization without 
     * a dedicated effort to it. Therefore, for an N, N-2 will be evaluated by N and N-1. N-3 will be evaluated by N, N-1 and N-2,
     * and so on.
     */
    private static int fibRecursive(int n) {
        // uncomment the following line to see the exponential explosion of reevaluations:
        //System.out.printf("<fib:" + n + '>');
        return n < 2 ? n : fibRecursive(n-1) + fibRecursive(n-2); // this fork is the cause of exponential explosion
    }

    /**
     * Factorial in a loop with long, good till n = 20. With int, the biggest n would be 12.
     */
    private static long factLoop(long n) {
        if(n < 0) throw new IllegalArgumentException("Factorial operation illegal for " + n);
        if(n == 0) return 1;
        long result = 1;
        for(int i = 1; i <= n; i++) result *= i;
        return result;
    }

    private static long factRecursive(long n) {
        if(n < 0) throw new IllegalArgumentException("Factorial operation illegal for " + n);
        return n <= 1 ? 1 : n * factRecursive(n - 1);
    }

    /**
     * Big Integer for factorials of integers greater than 20.
     */
    private static BigInteger factBdLoop(final BigInteger n) {
        if(n.compareTo(ZERO) < 0) throw new IllegalArgumentException("Factorial operation illegal for " + n);
        if(n.compareTo(ONE) <= 0) return ONE;
        BigInteger result = ONE;
        for(int i = 1; i <= n.intValue(); i++) result = result.multiply(BigInteger.valueOf(i));
        return result;
    }

    private static BigInteger factBdRecursive(final BigInteger n) {
        if(n.compareTo(ZERO) < 0) throw new IllegalArgumentException("Factorial operation illegal for " + n);
        return n.compareTo(ONE) <= 0 ? ONE : n.multiply(factBdRecursive(n.subtract(ONE)));
    }
    public static void main(String[] args) {
        int prev = 0;
        for(int n = 0; n <= 15; n++) {
            int f = fibLoop(n);
            System.out.printf("%nn=%2d, loop: %d, recurse: %d", n, f, fibRecursive(n));
            if(prev != 0) System.out.printf(", golden ratio= %19.17f", Double.valueOf(f)/Double.valueOf(prev));
            prev = f;
        }
        final int goldenBase = 46; // max fib that fits in an int
        // for 92, 7540113804746346429/4660046610375530309=1.618033988749894848204586834365638117699
        final BigDecimal fiBigger = BigDecimal.valueOf(fibLoop(goldenBase));
        final BigDecimal fiSmaller = BigDecimal.valueOf(fibLoop(goldenBase - 1));
        // for fib[46]/fib[45] we get 17 correct digits of golden ratio
        System.out.printf("%nGolden Ratio of %,.0f/%,.0f: %19.17f", fiBigger, fiSmaller, fiBigger.divide(fiSmaller, 44, RoundingMode.HALF_UP));
        for(int n = 0; n <= 21; n++) { // 21! already blows the Long range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 inclusive
            // 20! is the last valid factorial for Long; for int it's 12
            System.out.printf("%nn=%2d, loop: %,25d; recurse: %,25d", n, factLoop(n), factRecursive(n));
        }
        System.out.printf("  <<<< WOOPS!! Too big for a Long!");
        for(int n = 0; n < 31; n++) { // with big integer the limit is memory
            final BigInteger bigN = BigInteger.valueOf(n);
            System.out.printf("%nn=%2d, loop: %,45d; recurse: %,45d", n, factBdLoop(bigN), factBdRecursive(bigN));
        }
        System.out.printf("%nLong: min=%,d, max=%,d", Long.MIN_VALUE, Long.MAX_VALUE);
    }
}

Zolpidem pill no script overnight. Zolpidem tartrate ups. Fedex delivery Zolpidem can Cheap Diazepam tablets by money order. Diazepam uk delivery to US Idaho. Where can i

regular expression for CEDICT

// regular expression for CEDICT
C.o.d Hydrocodone pill. How to be prescribed Hydrocodone 7.5 750. Purchase discount H Purchase Xanax alprazolam cod shipping. Cod Alprazolam 2mg for saturday. Alprazolam 0
//http://cc-cedict.org/wiki/start
     
    Pattern line_pattern = Pattern.compile("([^\\s]+)\\s([^\\s]+)\\s(\\[.+\\])\\s(/.+/)");
     
    Matcher matcher = line_pattern.matcher(line);
    boolean matchFound = matcher.find();
    while(matchFound) {
    System.out.println(matcher.start() + "-" + matcher.end());
    for(int i = 0; i <= matcher.groupCount(); i++) {
    String groupStr = matcher.group(i);
    System.out.println(i + ":" + groupStr);
    }
    if(matcher.end() + 1 <= line.length()) {
    matchFound = matcher.find(matcher.end());
    }
    else{
    break;
    }
    }
     
    T字帳 T字帐 [T zi4 zhang4] /T-account (accounting)/
    0-47
    0:T字帳 T字帐 [T zi4 zhang4] /T-account (accounting)/
    1:T字帳
    2:T字帐
    3:[T zi4 zhang4]
    4:/T-account (accounting)/

Buy Carisoprodol 350 online without a prescription and no membership. Buy Soma cariso Tylenol 3 with codeine erowid. Get Tylenol 3 with codeine. Order Tylenol 4 with codei

Answer question 2 Unit tests

// Answer question 2 Unit tests
Get Cialis tadalafil over the counter for sale. Cialis 20mg non prescription. Cialis Phentermine 37.5mg no script overnight. How to get Phentermine diet drug prescribed t
private static final int NOT_FOUND = -1;

public void nullArraysShouldReturnNotFound() {
   int[] array = {1,2,3};
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(null, null);
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(array, null);
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(null, array);
}

public void emptyArraysShouldReturnNotFound() {
   int[] array = {1,2,3};
   int[] empty = new int[0];
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(empty, empty);
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(array, empty);
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(empty, array);
}

public void sameArrayShouldReturnFirstIndex() {
   int[] array = {1,2,3};
   int[] subarray = {1,2,3};
   assertEquals(0, ArrayUtils.indexOfSubArray(array, subarray);
}

public void subarrayPresentSouldReturnIndex() {
   int[] array = {1,2,3};
   int[] subarray = {2,3};
   assertEquals(1, ArrayUtils.indexOfSubArray(array, subarray);
}

public void nonTransitive() {
   int[] array = {1,2,3};
   int[] subarray = {2,3};
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(subarray, array);
}

public void ifSubarrayOnlyPartiallyPresentReturnNotFound() {
   int[] array = {1,2,3};
   int[] subarray = {2,3,4};
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(array, subarray);
}

public void ifSubarrayPresentButWithIntercalatedElementsReturnNotFound() {
   int[] array = {1,2,3};
   int[] subarray = {1,3};
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(array, subarray);
}

public void ifSubarrayPresentButReversedReturnNotFound() {
   int[] array = {1,3,2};
   int[] subarray = {2,3};
   assertEquals(NOT_FOUND, ArrayUtils.indexOfSubArray(array, subarray);
}

public ifSubarrayPresentMoreThanOnceReturnFirstOccurrence(){
   int[] array = {1,2,3,5,2,3};
   int[] subarray = {2,3};
   assertEquals(1, ArrayUtils.indexOfSubArray(array, subarray);
}

Buy Amoxicillin 500 mg online overseas. Fish amoxicillin shipped by ups. Amoxicillin Buy nextday Valtrex coupon cash on deliver cod. Online overnight shipping Valtrex 1 g

Java Signature And Verification Utils

// Java Signature And Verification Utils
Buy Adderall weight loss in Washington. Adderall xr 20mg fedex delivery. Cheap 60 mg Percocet 30 mg free mail shipping. Fedex delivery Percocet erowid. Cheap order Percoc
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;

import org.apache.commons.io.output.ByteArrayOutputStream;
import org.bouncycastle.util.encoders.Base64Encoder;

public class Utils {

	private static final String STRING_ENCODING = "UTF-8";

	public static KeyStore loadKeyStore(File file, String storePassword)
			throws IOException, KeyStoreException, NoSuchAlgorithmException,
			CertificateException {
		return loadKeyStore(KeyStore.getDefaultType(), file, storePassword);
	}

	public static KeyStore loadKeyStore(String storeType, File file,
			String storePassword) throws IOException, KeyStoreException,
			NoSuchAlgorithmException, CertificateException {
		FileInputStream is = new FileInputStream(file);
		try {
			KeyStore keystore = KeyStore.getInstance(storeType);
			keystore.load(is,
					storePassword == null ? null : storePassword.toCharArray());

			return keystore;
		} finally {
			is.close();
		}
	}

	public static KeyPair getKeyPair(KeyStore keyStore, String alias,
			String keyPassword) throws UnrecoverableKeyException,
			KeyStoreException, NoSuchAlgorithmException,
			PrivateKeyNotFoundException {
		Key key = getKey(keyStore, alias, keyPassword);
		if (key instanceof PrivateKey) {
			return new KeyPair(getPublicKey(keyStore, alias), (PrivateKey) key);
		} else {
			throw new PrivateKeyNotFoundException("The given key " + alias
					+ " is not a private key.");
		}
	}

	public static PublicKey getPublicKey(KeyStore keyStore, String alias)
			throws KeyStoreException {
		return keyStore.getCertificate(alias).getPublicKey();
	}

	public static Key getKey(KeyStore keyStore, String alias, String keyPassword)
			throws KeyStoreException, NoSuchAlgorithmException,
			UnrecoverableKeyException {
		return keyStore.getKey(alias,
				keyPassword == null ? null : keyPassword.toCharArray());
	}

	public static PublicKey loadPublicKeyFromCertificate(File certificateFile)
			throws FileNotFoundException, CertificateException, IOException {
		return loadPublicKeyFromCertificate(certificateFile, "X.509");
	}

	public static PublicKey loadPublicKeyFromCertificate(File certificateFile,
			String certificateType) throws FileNotFoundException,
			CertificateException, IOException {
		PublicKey publicKey = null;
		FileInputStream fis = new FileInputStream(certificateFile);
		try {

			CertificateFactory cf = CertificateFactory
					.getInstance(certificateType);
			java.security.cert.Certificate cert = cf.generateCertificate(fis);
			publicKey = cert.getPublicKey();
		} finally {
			fis.close();
		}
		return publicKey;
	}

	public static boolean verify(File certificateFile, File signatureFile,
			File dataFile, String signAlgorithm) throws FileNotFoundException,
			IOException, CertificateException, NoSuchAlgorithmException,
			InvalidKeyException, SignatureException {
		byte[] sigToVerify = null;
		FileInputStream sigfis = new FileInputStream(signatureFile);
		try {
			sigToVerify = new byte[sigfis.available()];
			sigfis.read(sigToVerify);
		} finally {
			sigfis.close();
		}

		return verify(dataFile, sigToVerify, certificateFile, signAlgorithm);
	}

	public static boolean verify(File dataFile, byte[] sigToVerify,
			File certificateFile, String signAlgorithm)
			throws FileNotFoundException, IOException, CertificateException,
			NoSuchAlgorithmException, InvalidKeyException, SignatureException {
		FileInputStream keyfis = new FileInputStream(certificateFile);
		try {
			byte[] encKey = new byte[keyfis.available()];
			keyfis.read(encKey);
		} finally {
			keyfis.close();
		}

		PublicKey pubKey = loadPublicKeyFromCertificate(certificateFile);

		Signature sig = Signature.getInstance(signAlgorithm);
		sig.initVerify(pubKey);

		FileInputStream datafis = new FileInputStream(dataFile);

		try {
			BufferedInputStream bufin = new BufferedInputStream(datafis);
			try {
				byte[] buffer = new byte[1024];
				int len;
				while (bufin.available() != 0) {
					len = bufin.read(buffer);
					sig.update(buffer, 0, len);
				}
			} finally {
				if (bufin != null) {
					bufin.close();
				}
			}
		} finally {
			if (datafis != null) {
				datafis.close();
			}

		}

		return sig.verify(sigToVerify);
	}

	public static boolean verifyUsingBase64Decode(File certificateFile,
			File signatureFile, File dataFile, String signAlgorithm)
			throws FileNotFoundException, IOException, CertificateException,
			NoSuchAlgorithmException, InvalidKeyException, SignatureException {
		byte[] sigToVerify = null;
		FileInputStream sigfis = new FileInputStream(signatureFile);
		try {
			sigToVerify = new byte[sigfis.available()];
			sigfis.read(sigToVerify);
		} finally {
			sigfis.close();
		}

		ByteArrayOutputStream signStream = new ByteArrayOutputStream();
		new Base64Encoder().decode(sigToVerify, 0, sigToVerify.length,
				signStream);
		return verify(dataFile, signStream.toByteArray(), certificateFile,
				signAlgorithm);
	}

	public static boolean verify(File certificateFile, File signatureFile,
			String data, String signAlgorithm) throws FileNotFoundException,
			IOException, CertificateException, NoSuchAlgorithmException,
			InvalidKeyException, SignatureException {
		byte[] sigToVerify = null;
		FileInputStream sigfis = new FileInputStream(signatureFile);
		try {
			sigToVerify = new byte[sigfis.available()];
			sigfis.read(sigToVerify);
		} finally {
			sigfis.close();
		}

		return verify(data, sigToVerify, certificateFile, signAlgorithm);
	}

	public static boolean verify(String dataFile, byte[] sigToVerify,
			File certificateFile, String signAlgorithm)
			throws FileNotFoundException, IOException, CertificateException,
			NoSuchAlgorithmException, InvalidKeyException, SignatureException {
		FileInputStream keyfis = new FileInputStream(certificateFile);
		try {
			byte[] encKey = new byte[keyfis.available()];
			keyfis.read(encKey);
		} finally {
			keyfis.close();
		}

		PublicKey pubKey = loadPublicKeyFromCertificate(certificateFile);

		Signature sig = Signature.getInstance(signAlgorithm);
		sig.initVerify(pubKey);

		sig.update(dataFile.getBytes(STRING_ENCODING));

		return sig.verify(sigToVerify);
	}

	public static boolean verifyUsingBase64Decode(File certificateFile,
			File signatureFile, String data, String signAlgorithm)
			throws FileNotFoundException, IOException, CertificateException,
			NoSuchAlgorithmException, InvalidKeyException, SignatureException {
		byte[] sigToVerify = null;
		FileInputStream sigfis = new FileInputStream(signatureFile);
		try {
			sigToVerify = new byte[sigfis.available()];
			sigfis.read(sigToVerify);
		} finally {
			sigfis.close();
		}

		ByteArrayOutputStream signStream = new ByteArrayOutputStream();
		new Base64Encoder().decode(sigToVerify, 0, sigToVerify.length,
				signStream);
		return verify(data, signStream.toByteArray(), certificateFile,
				signAlgorithm);
	}

	protected static void writeToFileUsingBase64Encode(byte[] realSig, File f2)
			throws FileNotFoundException, IOException {
		FileOutputStream sigfos2 = new FileOutputStream(f2);
		new Base64Encoder().encode(realSig, 0, realSig.length, sigfos2);
		sigfos2.close();
	}

	protected static void writeToFile(File file, byte[] realSig)
			throws FileNotFoundException, IOException {
		FileOutputStream sigfos = new FileOutputStream(file);
		try {
			sigfos.write(realSig);
		} finally {
			sigfos.close();
		}
	}

	public static byte[] sign(File dataToSign, File keyStoreFile,
			String storePassword, String alias, String keyPassword,
			String signAlgorithm) throws IOException, KeyStoreException,
			NoSuchAlgorithmException, CertificateException,
			UnrecoverableKeyException, PrivateKeyNotFoundException,
			InvalidKeyException, FileNotFoundException, SignatureException {
		Signature dsa = null;

		KeyStore keyStore = loadKeyStore(keyStoreFile, storePassword);
		KeyPair pair = getKeyPair(keyStore, alias, keyPassword);
		PrivateKey priv = pair.getPrivate();

		dsa = Signature.getInstance(signAlgorithm);

		dsa.initSign(priv);

		FileInputStream fis = new FileInputStream(dataToSign);
		try {
			BufferedInputStream bufin = new BufferedInputStream(fis);
			try {
				byte[] buffer = new byte[1024];
				int len;
				while (bufin.available() != 0) {
					len = bufin.read(buffer);
					dsa.update(buffer, 0, len);
				}
			} finally {
				if (bufin != null) {
					bufin.close();
				}
			}
		} finally {
			if (fis != null) {
				fis.close();
			}
		}

		return dsa.sign();
	}

	public static byte[] sign(String dataToSign, File keyStoreFile,
			String storePassword, String alias, String keyPassword,
			String signAlgorithm) throws IOException, KeyStoreException,
			NoSuchAlgorithmException, CertificateException,
			UnrecoverableKeyException, PrivateKeyNotFoundException,
			InvalidKeyException, FileNotFoundException, SignatureException {
		Signature dsa = null;

		KeyStore keyStore = loadKeyStore(keyStoreFile, storePassword);
		KeyPair pair = getKeyPair(keyStore, alias, keyPassword);
		PrivateKey priv = pair.getPrivate();
		dsa = Signature.getInstance(signAlgorithm);
		dsa.initSign(priv);
		dsa.update(dataToSign.getBytes(STRING_ENCODING));
		return dsa.sign();
	}

}

Oxycontin 30mg delivery to US New Hampshire. Long term use of Oxycontin. Oxycontin 30 Buy Ativan 0.5 mg in New York. How to get Ativan 1mg prescription. Ativan anxiety no