try { .../* SIMPLE UNPROTECT FRAGMENT */ .../* instantiate a DES cryptor */ MQeDESCryptor desC = new MQeDESCryptor( ); .../* instantiate an attribute using the DES cryptor */ MQeAttribute desA = new MQeAttribute( null, desC, null); .../* instantiate a (a helper) LocalSecure object */ MQeLocalSecure ls = new MQeLocalSecure( ); .../* open LocalSecure obj identifying target file and directory */ ls.open( ".\\", "TestSecureData.txt" ); /*instantiate an MQeFields object */ MQeFields myData =new MQeFields(); /*add some test data */ myData.putAscii("testdata","0123456789abcdef...."); .../* use LocalSecure write to protect data*/ ls.write( myData.dump(), desA, "It_is_a_secret" ) ); ... } catch ( Exception e ) { e.printStackTrace(); /* show exception */ } try { …/* SIMPLE UNPROTECT FRAGMENT */ …/* instantiate a DES cryptor */ MQeDESCryptor des2C = new MQeDESCryptor( ); …/* instantiate an attribute using the DES cryptor */ MQeAttribute des2A = new MQeAttribute( null, des2C, null); …/* instantiate a (a helper) LocalSecure object */ MQeLocalSecure ls2 = new MQeLocalSecure( ); …/* open LocalSecure obj identifying target file and directory */ ls2.open( ".\\", "TestSecureData.txt" ); …/* use LocalSecure read to restore from target and decode data*/ String outData = MQe.byteToAscii( ls2.read( desA2, "It_is_a_secret")); …/* show results…. */ trace ( "i: test data out = " + outData); … } catch ( Exception e ) { e.printStackTrace(); /* show exception */ }
try { …/*SIMPLE PROTECT FRAGMENT */ …/*instantiate a DES cryptor */ MQeDESCryptor desC = new MQeDESCryptor(); …/*instantiate an Attribute using the DES cryptor */ MQeAttribute attr = new MQeAttribute(null,desC,null); …/*instantiate a base Key object */ MQeKey localkey = new MQeKey(); …/*set the base Key object local key */ localkey.setLocalKey("my secret key"); …/*attach the key to the attribute */ attr.setKey(localkey); /*instantiate an MQeFields object */ MQeFields myData = new MQeFields(); /*attach the attribute to the data object */ myData.setAttribute(attr); /*add some test data */ myData.putAscii("testdata", "0123456789abcdef...."); trace ("i:test data in = " + myData.getAscii("testdata")); /*encode the data */ byte [] protectedData = myData.dump(); trace ("i:protected test data = " + MQe.byteToAscii(protectedData)); } catch (Exception e ) { e.printStackTrace(); /*show exception */ } try { …/*SIMPLE UNPROTECT FRAGMENT */ …/*instantiate a DES cryptor */ MQeDESCryptor desC2 = new MQeDESCryptor(); …/*instantiate an Attribute using the DES cryptor */ MQeAttribute attr2 = new MQeAttribute(null,desC2,null); …/*instantiate a base Key object */ MQeKey localkey2 = new MQeKey(); …/*set the base Key object local key */ localkey2.setLocalKey("my secret key"); …/*attach the key to the attribute */ attr2.setKey(localkey2 ); /*instantiate a new data object */ MQeFields myData2 = new MQeFields(); /*attach the attribute to the data object */ myData2.setAttribute(attr2 ); /*decode the data */ myData2.restore(protectedData ); /*show the unprotected test data */ trace ("i:test data out = " + myData2.getAscii("testdata")); } catch (Exception e ) { e.printStackTrace(); /*show exception */ }