import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class TextToImage
{

 public static void main(String[] args) throws IOException
 { 

  String s = "Hello All, Welcome to OSUM !!!";
  String fileName = "osumrocks";
  File file = new File("C:/" + fileName + ".BMP");
  Font font = new Font("Tahoma", Font.PLAIN, 11);
  FontRenderContext frc = new FontRenderContext(null, true, true);
  Rectangle2D bounds = font.getStringBounds(s, frc);
  int w = (int) bounds.getWidth();
  int h = (int) bounds.getHeight();
  BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
  Graphics2D g = image.createGraphics();
  g.setColor(Color.WHITE);
  g.fillRect(0, 0, w, h);
  g.setColor(Color.BLACK);
  g.setFont(font);
  g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
  RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
  RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  g.drawString(s, (float) bounds.getX(), (float) -bounds.getY());
  g.dispose();
  ImageIO.write(image, "BMP", file);

 }

}

AND


public BigInteger GenerateI(BigInteger g, BigInteger e)
 {
  //BigInteger i=IBECryptoUtil.pow(g, e);
  BigInteger i=g.modPow(e, m_n);
  return i;
 }

 

AND

import java.io.FileInputStream;
import java.security.MessageDigest;
 
public class SHACheckSumExample
{
    public static void main(String[] args)throws Exception
    {
         //sha1 해쉬 :  "SHA1"
        MessageDigest md = MessageDigest.getInstance("SHA-256")
        FileInputStream fis = new FileInputStream("c:\\loging.log");
 
        byte[] dataBytes = new byte[1024];
 
        int nread = 0;
        while ((nread = fis.read(dataBytes)) != -1) {
          md.update(dataBytes, 0, nread);
        };
        byte[] mdbytes = md.digest();
 
        //convert the byte to hex format method 1
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < mdbytes.length; i++) {
          sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
        }
 
        System.out.println("Hex format : " + sb.toString());
 
       //convert the byte to hex format method 2
        StringBuffer hexString = new StringBuffer();
    for (int i=0;i<mdbytes.length;i++) {
      hexString.append(Integer.toHexString(0xFF & mdbytes[i]));
    }
 
    System.out.println("Hex format : " + hexString.toString());
    }
}
AND

[파일 읽기]

==================================
파일읽기 권한 관련 클래스

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.security.PrivilegedExceptionAction;

public class PriviegedExceptionAction_I implements PrivilegedExceptionAction{
 public String filePath;
 
 public PriviegedExceptionAction_I(String filePath)
 {
  this.filePath=filePath;
 }
 
    public Object run() throws FileNotFoundException {
        return new FileInputStream(filePath);
    }
 
}

==================================
파일읽기 함수 구현

public byte[] getCertKey(String filePath)
 {
  byte[] baRequesterCert=null;
  try{
   PriviegedExceptionAction_I prv=new PriviegedExceptionAction_I(filePath);
   FileInputStream fis = (FileInputStream) AccessController.doPrivileged(prv);
   int size = fis.available();
   baRequesterCert=new byte[size];
      fis.read(baRequesterCert,0,size);
      fis.close();
  }catch (Exception ex){
   ex.printStackTrace();
  }
  return baRequesterCert;
 }

==================================
파일읽기 함수 호출

byte[] baRequesterCert=getCertKey("C:/JAVAWork/JDCAViewer/cert/signCert.der");



[파일저장]

==================================
파일저장 권한 관련 클래스

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.security.PrivilegedExceptionAction;

public class PriviegedExceptionAction_O implements PrivilegedExceptionAction{
 public String filePath;
 
 public PriviegedExceptionAction_O(String filePath)
 {
  this.filePath=filePath;
 }
 
    public Object run() throws FileNotFoundException {
        FileOutputStream fos=new FileOutputStream(filePath);
        return fos;
    }
}


==================================
파일저장 함수 구현

public void acrFileSave(String filePath,byte[] baARCCertReqMsg)
 {
  
  try{
   PriviegedExceptionAction_O prv=new PriviegedExceptionAction_O(filePath);
   FileOutputStream fos = (FileOutputStream) AccessController.doPrivileged(prv);
   fos.write(baARCCertReqMsg,0,baARCCertReqMsg.length);
   fos.close();
  }catch (Exception ex){
   ex.printStackTrace();
  }
  
 }


==================================
파일저장 함수 호출

acrFileSave(strFilePath+"/2.acq",baARCCertReqMsg);

이렇게 하면 해결됨

AND


import java.math.BigInteger;

public class Foo {
  public static void main(String[] args) {

  // 100자리 정수 정의
  BigInteger big = new BigInteger("1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

  // 위의 100자리 정수 출력
  System.out.println(big);
  System.out.println(); // 줄바꿈




  // 더하기 1 (BigInteger.ONE 은 1 이라는 상수)
  big = big.add(BigInteger.ONE);
  System.out.println(big);
  System.out.println(); // 줄바꿈

  // 더하기 2
  big = big.add(BigInteger.valueOf(2));
  System.out.println(big);
  System.out.println(); // 줄바꿈

  // 빼기 3
  big = big.subtract(BigInteger.valueOf(3));
  System.out.println(big);
  System.out.println(); // 줄바꿈

  // 곱하기 2
  big = big.multiply(BigInteger.valueOf(2));
  System.out.println(big);
  System.out.println(); // 줄바꿈

  // 나누기 2 (실수가 아닌 항상 BigInteger 정수를 반환)
  big = big.divide(BigInteger.valueOf(2));
  System.out.println(big);
  System.out.println(); // 줄바꿈


  // 곱하기 0 (BigInteger.ZERO 는 0 이라는 상수)
  big = big.multiply(BigInteger.ZERO);
  System.out.println(big);
  System.out.println(); // 줄바꿈

  }
}


AND