@@ -462,7 +462,7 @@ static string Quote (string unsafeString)
462462 /// if your database is encrypted.
463463 /// This only has an effect if you are using the SQLCipher nuget package.
464464 /// </summary>
465- /// <param name="key">Ecryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
465+ /// <param name="key">Encryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
466466 void SetKey ( string key )
467467 {
468468 if ( key == null )
@@ -477,7 +477,7 @@ void SetKey (string key)
477477 /// if your database is encrypted.
478478 /// This only has an effect if you are using the SQLCipher nuget package.
479479 /// </summary>
480- /// <param name="key">256-bit (32 byte) ecryption key data</param>
480+ /// <param name="key">256-bit (32 byte) encryption key data</param>
481481 void SetKey ( byte [ ] key )
482482 {
483483 if ( key == null )
@@ -488,6 +488,32 @@ void SetKey (byte[] key)
488488 ExecuteScalar < string > ( "pragma key = \" x'" + s + "'\" " ) ;
489489 }
490490
491+ /// <summary>
492+ /// Change the encryption key for a SQLCipher database with "pragma rekey = ...".
493+ /// </summary>
494+ /// <param name="key">Encryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
495+ public void SetReKey ( string key )
496+ {
497+ if ( key == null )
498+ throw new ArgumentNullException ( nameof ( key ) ) ;
499+ var q = Quote ( key ) ;
500+ ExecuteScalar < string > ( "pragma rekey = " + q ) ;
501+ }
502+
503+ /// <summary>
504+ /// Change the encryption key for a SQLCipher database.
505+ /// </summary>
506+ /// <param name="key">256-bit (32 byte) or 384-bit (48 bytes) encryption key data</param>
507+ public void SetReKey ( byte [ ] key )
508+ {
509+ if ( key == null )
510+ throw new ArgumentNullException ( nameof ( key ) ) ;
511+ if ( key . Length != 32 && key . Length != 48 )
512+ throw new ArgumentException ( "Key must be 32 bytes (256-bit) or 48 bytes (384-bit)" , nameof ( key ) ) ;
513+ var s = String . Join ( "" , key . Select ( x => x . ToString ( "X2" ) ) ) ;
514+ ExecuteScalar < string > ( "pragma rekey = \" x'" + s + "'\" " ) ;
515+ }
516+
491517 /// <summary>
492518 /// Enable or disable extension loading.
493519 /// </summary>
0 commit comments