public static char[] encodeRawKey(byte[] raw_key){
  if (raw_key.length != 32)   throw new IllegalArgumentException("provided key not 32 bytes (256 bits) wide");
  final String kPrefix;
  final String kSuffix;
  if (sqlcipher_uses_native_key) {
    Log.d(TAG,"sqlcipher uses native method to set key");
    kPrefix="x'";
    kSuffix="'";
  }
 else {
    Log.d(TAG,"sqlcipher uses PRAGMA to set key - SPECIAL HACK IN PROGRESS");
    kPrefix="x''";
    kSuffix="''";
  }
  final char[] key_chars=encodeHex(raw_key,HEX_DIGITS_LOWER);
  if (key_chars.length != 64)   throw new IllegalStateException("encoded key is not 64 bytes wide");
  char[] kPrefix_c=kPrefix.toCharArray();
  char[] kSuffix_c=kSuffix.toCharArray();
  CharBuffer cb=CharBuffer.allocate(kPrefix_c.length + kSuffix_c.length + key_chars.length);
  cb.put(kPrefix_c);
  cb.put(key_chars);
  cb.put(kSuffix_c);
  return cb.array();
}

public static char [ ] encodeRawKey ( byte [ ] raw_key ) { if ( raw_key . length != 32 ) throw new IllegalArgumentException ( "provided key not 32 bytes (256 bits) wide" ) ; final String kPrefix ; final String kSuffix ; if ( sqlcipher_uses_native_key ) { Log . d ( TAG , "sqlcipher uses native method to set key" ) ; kPrefix = "x'" ; kSuffix = "'" ; } else { Log . d ( TAG , "sqlcipher uses PRAGMA to set key - SPECIAL HACK IN PROGRESS" ) ; kPrefix = "x''" ; kSuffix = "''" ; } final char [ ] key_chars = encodeHex ( raw_key , HEX_DIGITS_LOWER ) ; if ( key_chars . length != 64 ) throw new IllegalStateException ( "encoded key is not 64 bytes wide" ) ; char [ ] kPrefix_c = kPrefix . toCharArray ( ) ; char [ ] kSuffix_c = kSuffix . toCharArray ( ) ; CharBuffer cb = CharBuffer . allocate ( kPrefix_c . length + kSuffix_c . length + key_chars . length ) ; cb . put ( kPrefix_c ) ; cb . put ( key_chars ) ; cb . put ( kSuffix_c ) ; return cb . array ( ) ; }
formats a byte sequence into the literal string format expected by sqlcipher : hex ' hex encoded bytes ' the key data must be 256 bits ( 32 bytes ) wide . the key data will be formatted into a 64 character hex string with a special prefix and suffix sqlcipher uses to distinguish raw key data from a password .
