Demo entry 6100889

1

   

Submitted by anonymous on Sep 29, 2016 at 13:24
Language: Java. Code size: 2.3 kB.

public void testSingleColVarCharEncDecTest()
		{
			Connection conn 					= null;
			String sTargetTableName 			= "testSingleColVarChar";
			String sTargetColumnName 			= "VAR_CHR";
			testSingleColEncDecTest obj 		= new testSingleColEncDecTest();
			SimpleSafeDB sSdb					= null;
			String sPolicyUserName				= "SAFEDB";
			String sPolicyTableName				= "TTAUSER.SINGLE_COL_TABLE";
			String sPolicyColumnName			= "sVar";
		
			System.out.println("Testcase : " + testUtility.getCurrentMethodName() + " started");  
			
			try {
				// DB 암호화 제품 수행을 위한 초기 셋팅 수행
				sSdb = SimpleSafeDB.getInstance();
				obj.init_api_module(sSdb);
				
				// DBMS 연결 생성
				conn = testUtility.getDBMSConnection(DbmsType.Tibero, testConstant.DBMS_USER, testConstant.DBMS_USER_PWD);
		
				// 테스트 데이터 삽입
				testUtility.createSingleColStringData(conn, sTargetTableName, sTargetColumnName + " VARCHAR2(" + testConstant.DEFAULT_TEST_STR_LEN + ")", 
						testConstant.DEFAULT_TEST_STR_LEN, testConstant.DEFAULT_TEST_RECORDS);
		
				for (int i = 0; i < testConstant.DEFAULT_TEST_ATTEMPT_NUM; i++)
				{
					// 암호화 전 컬럼 데이터 획득 
					String aOriginalData = testUtility.getColStrValue(conn, sTargetTableName, sTargetColumnName, 
							testUtility.genRandomInt(testConstant.DEFAULT_TEST_RECORDS, 1)); 
					System.out.println("Original Data : " + aOriginalData);
		
					// 컬럼 데이터 암호화
					String encData = obj.encryptStr(sSdb, sPolicyUserName, sPolicyTableName, sPolicyColumnName, aOriginalData);
					System.out.println("Encrypted Data : " + encData);
		
					// 암호화 데이터 복호화
					String aDecData = obj.decryptStr(sSdb, sPolicyUserName, sPolicyTableName, sPolicyColumnName, encData);
					System.out.println("Decrypted Data : " + aDecData);
		
					// 암호화 데이터 복호화 및 원본 값과 비교   		
					if(aOriginalData.equals(aDecData) == false)
					{
						Assert.fail("Varchar Enc/Dec test has been failed : un-matched data.");
					}
				}
				
				
			} catch(Exception e) {
				e.printStackTrace();
				Assert.fail(e.getMessage());
			} finally {
				// 사용 테이블 제거
				testUtility.dropTable(conn, sTargetTableName);
				try { if(conn != null) conn.close(); } catch(Exception e) { }
				try { if(sSdb != null) sSdb.logout(); } catch(Exception e) { }
			}
		}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).