C# String.format 사용법

Programming/C,CPP,CS 2021. 3. 17. 14:15 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

String Format for Int [C#]

Integer numbers can be formatted in .NET in many ways. You can use static method String.Format or instance method int.ToString. Following examples show how to align numbers (with spaces or zeroes), how to format negative numbers or how to do custom formatting like phone numbers.

Add zeroes before number

To add zeroes before a number, use colon separator „:“ and write as many zeroes as you want.

[C#]
String.Format("{0:00000}", 15); // "00015" String.Format("{0:00000}", -15); // "-00015"

Align number to the right or left

To align number to the right, use comma „,“ followed by a number of characters. This alignment option must be before the colon separator.

[C#]
String.Format("{0,5}", 15); // " 15" String.Format("{0,-5}", 15); // "15 " String.Format("{0,5:000}", 15); // " 015" String.Format("{0,-5:000}", 15); // "015 "

Different formatting for negative numbers and zero

You can have special format for negative numbers and zero. Use semicolon separator „;“ to separate formatting to two or three sections. The second section is format for negative numbers, the third section is for zero.

[C#]
String.Format("{0:#;minus #}", 15); // "15" String.Format("{0:#;minus #}", -15); // "minus 15" String.Format("{0:#;minus #;zero}", 0); // "zero"

Custom number formatting (e.g. phone number)

Numbers can be formatted also to any custom format, e.g. like phone numbers or serial numbers.

[C#]
String.Format("{0:+### ### ### ###}", 447900123456); // "+447 900 123 456" String.Format("{0:##-####-####}", 8958712551); // "89-5871-2551"

 

 

출처 : www.csharp-examples.net/string-format-int/

 

String Format for Int [C#]

String Format for Int [C#] Integer numbers can be formatted in .NET in many ways. You can use static method String.Format or instance method int.ToString. Following examples show how to align numbers (with spaces or zeroes), how to format negative numbers

www.csharp-examples.net

 

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

using System.Diagnostics;



Stopwatch sw = new Stopwatch();


sw.Start();





// TODO






sw.Stop();






MessageBox.Show(sw.ElapsedMilliseconds.ToString() + "ms");



MessageBox.Show(sw.Elapsed.Hour.ToString() + "Minute");

MessageBox.Show(sw.Elapsed.Minute.ToString() + "Minute");

MessageBox.Show(sw.Elapsed.Second.ToString() + "Minute");







OpenSSL x86 Build

Programming/C,CPP,CS 2016. 10. 28. 15:39 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

OpenSSL x86 Build


Windows7 64bit


Visual Studio 2013






1. download openssl 

openssl-1.0.2j.tar.gz


http://openssl.org/source/





extract to D:\openssl-1.0.2j






2. download/install ActivePerl for Win64 


http://www.activestate.com/activeperl/downloads





C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts


execute VS2013 x86 네이티브 도구 명령 프롬프트, VS2013 x86 Native Tools Command Prompt





change directory to D:\openssl-1.0.2j


3. Setting Target openssldir


perl Configure VC-WIN32 no-idea no-mdc2 no-rc5 --prefix=d:\openssl32bit no-shared no-asm threads



no-asm 옵션을 추가하지 않으면 nasm 을 설치하여야 하므로.....


no-idea, no-mdc2, no-rc5 옵션은 특허가 포함되어있는 모듈이므로


꼭 필요하지 않다면 사용하지 않는 것이 좋습니다.



참고 : http://greenfishblog.tistory.com/81



사진은 64비트 버전의 것을 복붙을 하여서 명령어가 다릅니다. 참고바랍니다.








4. Setting complie enviroment


ms\do_ms








5. Complie


nmake -f ms\ntdll.mak install






설치 명령어는 사실


openssl 폴더에 있는



INSTALL.W64 , INSTALL.W32 만 따라하셔도 충분히 가능합니다.








'Programming > C,CPP,CS' 카테고리의 다른 글

임계영역 설정 Ctirical Section  (0) 2016.11.07
Jsoncpp 주의 사항  (0) 2016.11.01
pjproject-2.5.5  (0) 2016.10.14
pjsip Building for Microsoft Windows  (1) 2016.10.12
oRTP  (0) 2016.10.11
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Java SocketServer control Image, DBConnect, String




package com.tistory.tansanc;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import javax.imageio.ImageIO;

class DBConnect {
	ResultSet rs = null;
	Connection conn = null;
	Statement stmt = null;
	public DBConnect() {
		try {
			String url = "jdbc:sqlserver://192.168.10.17:1433;DatabaseName=MSSQLSERVER";
			
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection(url, "sa", "1234");
			stmt = conn.createStatement();
			

		} catch (Exception e) {

		}
	}

	public void finalize() {
		try {
			rs.close();
			stmt.close();
			conn.close();
		} catch (Exception e) {

		}
	}
}

class PerClientThread extends Thread {
	Socket s;
	static ArrayList socketArray = new ArrayList();
	static DBConnect dbc;
	
	public PerClientThread()
	{
		
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub

		socketArray.add(s);
		BufferedReader br;

		
		try {
			br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			String temp;
			while ((temp = br.readLine()) != null) {
				// DB Query
				if (temp.startsWith("select")) {
					
					try {
						dbc.rs = dbc.stmt.executeQuery("SELECT * FROM [dbo].[TESTDB]");

						while (dbc.rs.next()) {
							String field1 = dbc.rs.getString("Date");
							String field2 = dbc.rs.getString("FileName");
							System.out.println(field1);
							System.out.println(field2);

							java.sql.Blob blb = dbc.rs.getBlob("Image");
							byte[] imagebytes = blb.getBytes(0, (int) blb.length());
							BufferedImage theImage = ImageIO.read(new ByteArrayInputStream(imagebytes));

						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					temp = "SQL:" + temp;
					System.out.println(temp);
				}
				// Arduino
				else if (temp.startsWith("insert"))
				{
					
				}
				// Arduino
				else if (temp.startsWith("image"))
				{

			        int size = Integer.parseInt(br.readLine());
			        
			        DataInputStream inputStream = new DataInputStream(s.getInputStream());
			        
			        byte[] imageAr = new byte[size];
			        inputStream.read(imageAr, 0, size);

			        BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageAr));

			        System.out.println("Received " + image.getHeight() + "x" + image.getWidth() + ": " + System.currentTimeMillis());
			        ImageIO.write(image, "png", new File("C:\\test2.png"));


				}
				// Arduino
				else if (temp.startsWith("to"))
				{
					
				}
				System.out.print(s.getInetAddress() + " : ");
				System.out.println(temp);
				for (int i = 0; i < socketArray.size(); i++) {
					PrintWriter os = new PrintWriter(socketArray.get(i).getOutputStream(), true);
					os.print(s.getInetAddress() + " : ");
					os.println(temp);
				}
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		super.run();
	}
}

public class Server {
	public static void main(String[] args) throws Exception {
 
		System.out.println("Server Side");
		ServerSocket ss = new ServerSocket(33333);
		Socket s;
		while (true) {
			s = ss.accept();
			PerClientThread pct = new PerClientThread();
			pct.s = s;
			pct.dbc = new DBConnect();
			pct.start();
		}

	}
}










Client.java
package com.tistory.tansanc;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;

class MyFrame extends JFrame {
	public static JTextArea textArea;
	JTextField textField;
	PrintWriter out;
	Socket s;

	public MyFrame() {
		textArea = new JTextArea();
		textField = new JTextField();
		add(BorderLayout.CENTER, textArea);
		add(BorderLayout.SOUTH, textField);
		textField.addActionListener(new FieldListener());
		setSize(300, 200);
		setTitle("채팅프로그램 Client");
		setVisible(true);
		// GUI를 설계한다.
	}

	class FieldListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if (textField.getText().compareTo("image") == 0) {

				BufferedImage image;
				ByteArrayOutputStream byteArrayOutputStream = null;
				DataOutputStream os = null;
				try {
					image = ImageIO.read(new File("C:\\test.png"));
					byteArrayOutputStream = new ByteArrayOutputStream();
					ImageIO.write(image, "png", byteArrayOutputStream);
					os = new DataOutputStream(s.getOutputStream());
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				try {
					int size = byteArrayOutputStream.size();
					out.println("image");
					out.println(size);
					os.write(byteArrayOutputStream.toByteArray());
					os.flush();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

			} else {
				out.println(textField.getText());
				textField.setText("");
			}
			// 메세지 보내기
		}
	}
}

class SendThread extends Thread {
	PrintWriter out;

	public SendThread(PrintWriter out) {
		this.out = out;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		super.run();
	}
}

class RecvThread extends Thread {
	BufferedReader in;

	public RecvThread(BufferedReader in) {
		this.in = in;
	}

	@Override
	public void run() {
		String temp;
		try {
			while ((temp = in.readLine()) != null) {

				MyFrame.textArea.setText(MyFrame.textArea.getText() + "\n" + temp);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class ClientModule {
	MyFrame mFrame;
	SendThread mSendThread;
	RecvThread mRecvThread;
	Socket s;

	// 서버에 패킷을 보내는 Thread
	// 서버로부터 패킷을 받는 Thread
	public ClientModule() // 준비
	{

		try {
			s = new Socket("192.168.10.17", 33333);
			PrintWriter out = new PrintWriter(s.getOutputStream(), true);
			BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			mFrame = new MyFrame(); // GUI 객체
			mFrame.s = s;
			mFrame.out = out;
			mSendThread = new SendThread(out);
			mRecvThread = new RecvThread(in);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	void start() // 시작
	{
		mSendThread.start();
		mRecvThread.start();
	}
}

public class Client {
	public static void main(String[] args) {
		ClientModule cm = new ClientModule();
		// 초기화 작업
		cm.start();
		// Thread.start();
	}
}





Hiredis Subscribe/Publish with CWinThread

Programming/Redis 2016. 10. 5. 14:01 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Hiredis Subscribe/Publish



CWinThread 를 이용한 구현




struct event_base *base = event_base_new();

class CRedisConnect : public CWinThread
{
public:
	redisAsyncContext *c;
	// CWinThread extends
	virtual BOOL InitInstance();
	virtual int Run();
};

BOOL CRedisConnect::InitInstance()
{
	return TRUE;
}

int CRedisConnect::Run()
{
	c = redisAsyncConnect(redisServerIP, redisServerPort);
	if (c->err) {
		/* Let *c leak for now... */
		return 1;
	}
	redisLibeventAttach(c, base);

	int re2 = redisAsyncCommand(c, getCallback, NULL, "SUBSCRIBE foo");

	event_base_dispatch(base);

	return (0);
}



void getCallback(redisAsyncContext *c, void *r, void *privdata) {

	redisReply *reply = (redisReply *)r;
	if (reply == NULL)
	{
		LOG4CXX_DEBUG(g_log, "Subcribe reply == NULL");
	}
	// reply->type
	// #define REDIS_REPLY_STRING 1
	// #define REDIS_REPLY_ARRAY 2
	// #define REDIS_REPLY_INTEGER 3
	// #define REDIS_REPLY_NIL 4
	// #define REDIS_REPLY_STATUS 5
	// #define REDIS_REPLY_ERROR 6
	else if (reply->type == REDIS_REPLY_ERROR)
	{
		LOG4CXX_DEBUG(g_log, "Subcribe reply type == REDIS_REPLY_ERROR");
	}
	else if (reply->type == REDIS_REPLY_ARRAY)
	{
		LOG4CXX_DEBUG(g_log, "reply->elements == " << reply->elements);
		LOG4CXX_DEBUG(g_log, "reply->len == " << reply->len);
		for (int i = 0; i < reply->elements; i++)
		{
			if (reply->element[i]->str != NULL)
			LOG4CXX_DEBUG(g_log, "Subcribe reply array [" << i << "] == " << reply->element[i]->str);			
		}		
	}
	else
	{
		LOG4CXX_DEBUG(g_log, "getCallback reply str : " << reply->str);
	}
}

'Programming > Redis' 카테고리의 다른 글

Hiredis SMEMBERS 활용  (0) 2017.01.24
Redis Client Connect Test  (0) 2016.10.26
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28

MFC Alert MessageBox2

Programming/MFC 2016. 9. 6. 10:47 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

      int MessageBox(
   LPCTSTR lpszText,
   LPCTSTR lpszCaption = NULL,
   UINT nType = MB_OK 
);

lpszText

가리키는 있는 CString 개체 또는 표시 되는 메시지에 포함 된 null로 끝나는 문자열입니다.

lpszCaption

가리키는 있는 CString 개체 또는 null로 끝나는 문자열에 대 한 캡션을 메시지 상자를 사용할 수 있습니다. 경우 lpszCaption  NULL, 기본 캡션을 "오류"를 사용 합니다.

nType

콘텐츠 및 메시지 상자의 동작을 지정합니다.


전역 함수 사용 AfxMessageBox 응용 프로그램에서 메시지 상자를 구현 하려면이 멤버 함수를 대신 합니다.

다음은 메시지 상자에 사용할 수 있는 다양 한 시스템 아이콘입니다.

중지(x) 아이콘

MB_ICONHANDMB_ICONSTOP, 및 MB_ICONERROR

도움말(?) 아이콘

MB_ICONQUESTION

중요(!) 아이콘

MB_ICONEXCLAMATION 및 MB_ICONWARNING

정보(i) 아이콘

MB_ICONASTERISK 및 MB_ICONINFORMATION









void CMainFrame::OnDisplayErrorMessage()
{
   // This displays a message box with the title "Error"
   // and the message "Help, Something went wrong."
   // The error icon is displayed in the message box, along with
   // an OK button.
   MessageBox(_T("Help, Something went wrong."), _T("Error"), 
      MB_ICONERROR | MB_OK);
}




'Programming > MFC' 카테고리의 다른 글

MFC Dialog Modal  (0) 2016.09.22
MFC Modal and Modeless Dialog Boxes  (0) 2016.09.06
MFC Alert MessageBox  (0) 2016.09.06
MFC Drag And Drop FileName 만 추출  (0) 2016.08.30
MFC File Icon Drag and Drop  (0) 2016.08.30
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

CPP aes128 cbc mode Encryption Decryption



AES


Encryption Block  : 

128 비트

192 비트 

256 비트


Mode :    

1. ECB ( Electric Code Book )

http://jo.centis1504.net/wp-content/uploads/2010/11/Encryption-ECB_MODE.swf




2. CBC ( Cipher Block Chaining )

http://jo.centis1504.net/wp-content/uploads/2010/11/Encryption-CBC_MODE.swf





3. OFB ( Output Feed Back )

http://jo.centis1504.net/wp-content/uploads/2010/11/Encryption-OFB_MODE.swf



4. CFB ( Cipher Feed Back )



5. CTR ( CounTeR )



모드별 설명은


관련 자료 참고 : http://www.parkjonghyuk.net/lecture/modernCrypto/lecturenote/chap04.pdf




구현에서는 CTR 모드로 구현하였다.






개발 환경 : Windows 7 64bit, VS 2013



최신버전으로 직접 빌드하시려면 아래의 링크를 참조하시기 바랍니다.


귀찮으신 분은 빌드된 버전을 사용합시다.


OpenSSL 빌드 : http://yokkohama.tistory.com/entry/OpenSSL-%EB%B9%8C%EB%93%9C%ED%95%98%EA%B8%B0-Visual-Studio-2010-%EB%98%90%EB%8A%94-libeay32dll-ssleay32dll-%EB%8B%A4%EC%9A%B4%EB%A1%9C%EB%93%9C



"openssl-1.0.1f_vc_no-idea no-mdc2 no-rc5_build.zip" 는 no-idea no-mdc2 no-rc5  로 빌드된, 특허문제가 해결 된 바이너리입니다.


openssl-1.0.1f_vc_no-idea no-mdc2 no-rc5_build.zip



압축 해제 후 파일을 프로젝트 폴더로 이동



프로젝트속성 > VC++ 디렉터리 > 디렉터리 설정 (포함 디렉터리, 라이브러리 디렉터리)






별도의 클래스를 만들어 사용 하였습니다.







#pragma once

#include 
#include 
#include 
#include 


struct ctr_state {
	unsigned char ivec[AES_BLOCK_SIZE];
	unsigned int num;
	unsigned char ecount[AES_BLOCK_SIZE];
};



class CAESCTR
{
public:
	AES_KEY key;
	int BYTES_SIZE = 1024;
	int KEY_SIZE = 128;
	unsigned char ckey[32];
	unsigned char iv[8];
	int init_ctr(struct ctr_state *state, const unsigned char iv[8]);
	void encrypt(unsigned char *indata, unsigned char *outdata, int bytes_read);
	void encrypt(CString& indata, CString& outdata, int bytes_read);
	CAESCTR();
	CAESCTR::CAESCTR(unsigned char* iv, unsigned char* ckey);
	~CAESCTR();
};







#include "stdafx.h"
#include "AESCTR.h"

int CAESCTR::init_ctr(struct ctr_state *state, const unsigned char iv[8]){
	state->num = 0;
	memset(state->ecount, 0, AES_BLOCK_SIZE);
	memset(state->ivec + 8, 0, 8);
	memcpy(state->ivec, iv, 8);

	return 0;
}
// encrypt twice  == decrypt

void CAESCTR::encrypt(unsigned char *indata, unsigned char *outdata, int bytes_read){

	int i = 0;
	int mod_len = 0;

	AES_set_encrypt_key(ckey, KEY_SIZE, &key);

	if (bytes_read < BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
		return;
	}
	// loop block size  = [ BYTES_SIZE ]
	for (i = BYTES_SIZE; i <= bytes_read; i += BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, BYTES_SIZE, &key, state.ivec, state.ecount, &state.num);
		indata += BYTES_SIZE;
		outdata += BYTES_SIZE;
	}

	mod_len = bytes_read % BYTES_SIZE;
	if (mod_len != 0){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, mod_len, &key, state.ivec, state.ecount, &state.num);
	}
}

void CAESCTR::encrypt(CString& instr, CString& outstr, int bytes_read){

	int i = 0;
	int mod_len = 0;
	unsigned char *indata;
	unsigned char *outdata;

	indata = (unsigned char *)malloc(instr.GetLength() + 1);
	outdata = (unsigned char *)malloc(instr.GetLength() + 1);



	strncpy((char*)indata, (LPSTR)(LPCSTR)instr, instr.GetLength());
	indata[instr.GetLength()] = NULL;


	

	AES_set_encrypt_key(ckey, KEY_SIZE, &key);

	if (bytes_read < BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

		outdata[instr.GetLength()] = NULL;
		outstr = outdata;
		return;
	}
	// loop block size  = [ BYTES_SIZE ]
	for (i = BYTES_SIZE; i <= bytes_read; i += BYTES_SIZE){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, BYTES_SIZE, &key, state.ivec, state.ecount, &state.num);
		indata += BYTES_SIZE;
		outdata += BYTES_SIZE;
	}

	mod_len = bytes_read % BYTES_SIZE;
	if (mod_len != 0){
		struct ctr_state state;
		init_ctr(&state, iv);
		AES_ctr128_encrypt(indata, outdata, mod_len, &key, state.ivec, state.ecount, &state.num);
	}
	outdata[instr.GetLength()] = NULL;
	outstr = outdata;
}

CAESCTR::CAESCTR()
{
	unsigned char temp_iv[8] = { 0x66, 0x61, 0x63, 0x65, 0x73, 0x65, 0x61, 0x00 };
	memcpy(iv, temp_iv, 8);

	unsigned char temp_ckey[32] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
		0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
		0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
		0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 }; // 32bytes = AES256, 16bytes = AES128
	memcpy(ckey, temp_ckey, 32);
}

CAESCTR::CAESCTR(unsigned char* iv, unsigned char* ckey)
{
	memcpy(this->iv, iv, 8);
	memcpy(this->ckey, ckey, 32);
}

CAESCTR::~CAESCTR()
{
}






그리고, 프로젝트 속성에서


구성 속성 > 문자 집합 > 설정 안 함


으로 하여서 사용하였습니다.



사용예시










void CPasswordEncoderDlg::OnEnChangeEdit1()
{
	// TODO:  RICHEDIT 컨트롤인 경우, 이 컨트롤은
	// CDialogEx::OnInitDialog() 함수를 재지정 
	//하고 마스크에 OR 연산하여 설정된 ENM_CHANGE 플래그를 지정하여 CRichEditCtrl().SetEventMask()를 호출하지 않으면
	// 이 알림 메시지를 보내지 않습니다.

	// TODO:  여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CAESCTR m_AESCTR;

	CString editText;
	m_Edit1.GetWindowTextA(editText);
		
	int editTextLength = editText.GetLength();

	unsigned char* editTextCharSeq;
	editTextCharSeq = (unsigned char *)malloc(editTextLength+1);

	strncpy((char*)editTextCharSeq, (LPSTR)(LPCSTR)editText, editTextLength);
	editTextCharSeq[editTextLength] = NULL;

	unsigned char* outTextCharSeq;
	outTextCharSeq = (unsigned char *)malloc(editTextLength + 1);

	m_AESCTR.encrypt(editTextCharSeq, outTextCharSeq, editTextLength);
	outTextCharSeq[editTextLength] = NULL;
	
	editText = outTextCharSeq;
	m_Edit2.SetWindowTextA(editText);
	
	m_AESCTR.encrypt(editText, editText, editTextLength);

	m_Edit3.SetWindowTextA(editText);

	free(editTextCharSeq);
	free(outTextCharSeq);
}










'Programming > C,CPP,CS' 카테고리의 다른 글

openssl AES encrypt (AES_ctr128_encrypt)  (0) 2016.09.19
openssl AES Mode : ECB, CBC, CFB, OFB, CTR  (0) 2016.09.05
CDateTimeCtrl 사용법  (0) 2016.08.25
Apache License, Version 2.0  (0) 2016.08.22
Log4cxx ChainSaw Appender  (0) 2016.08.22
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

if (media_player_ye_state.get(index) == false) {

media_player_ye_state.set(index, true);


if (media_player_ye_filePath.get(index) == "") {

media_player_ye[index] = MediaPlayer.create(

mContext, raw);

} else {

media_player_ye[index] = new MediaPlayer();

try {

media_player_ye[index]

.setDataSource(media_player_ye_filePath

.get(index));

} catch (Exception e) {

e.printStackTrace();

}

}

media_player_ye[index]

.setOnPreparedListener(mPreparedListener);

media_player_ye[index].setVolume(

media_player_ye_Volume, media_player_ye_Volume);

media_player_ye[index].setLooping(true); // 반복재생

alButton.get(buttonNum).setPressed(true);

try {

media_player_ye[index].prepare();

} catch (Exception e) {

e.printStackTrace();

}

}

return true;

case MotionEvent.ACTION_UP:

alButton.get(buttonNum).setPressed(false);

media_player_ye_state.set(index, false);

try {

media_player_ye[index].release();

} catch (Exception e) {

media_player_ye[index] = null;

e.printStackTrace();

}

return true;

}

return false;

}