Details
-
Type: Improvement
-
Status: Closed
-
Priority: Major
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
The following could be added to XStream.java to provide simple obfuscation of classes...I have done this to our implementation and it appears to work reasonably well.
public void aliasFields(Class type) {
Field[] fields = type.getDeclaredFields();
StringBuffer sb = new StringBuffer();
sb.append( 'a' );
for ( int i = 0; i < fields.length; i++ )
{ Field field = fields[i]; aliasField( String.valueOf( sb.toString() ), type, field.getName() ); incrementAlias( sb ); }}
private static char incrementAlias(char c)
{ return ( c == 'z' ? 'a' : ++c ); }private static void incrementAlias(StringBuffer buf) {
char c;
int i = buf.length() - 1;
do {
c = incrementAlias( buf.charAt( i ) );
buf.setCharAt( i, c );
if ( i == 0 && c == 'a' )
i--;
}
while ( c == 'a' );
}
Issue Links
- supercedes
-
XSTR-224 Field obfuscation
I hadn't investigated compliance with my comment about adding obfuscation....clearly using numbers is not an option. This implementation seems reasonable.