/// <summary> /// Create a copy of the byte array. /// </summary> /// <remarks> /// If this instance is read-only, /// the copy will not be read-only. /// </remarks> /// <returns>A copy of the byte array.</returns> /// <exception cref="IllegalStateException">If the byte array has been disposed</exception> public GuardedByteArray Copy() { SecureString t2 = _target.Copy(); GuardedByteArray rv = new GuardedByteArray(t2); return(rv); }
/// <summary> /// Decrypts the value of a <seealso cref="GuardedByteArray"/>. /// </summary> /// <param name="guardedByteArray"> /// the guarded byte array value. </param> /// <returns> the clear byte array value.</returns> /// <remarks>Since 1.4</remarks> public static byte[] Decrypt(GuardedByteArray guardedByteArray) { byte[] result = null; guardedByteArray.Access(new GuardedByteArray.LambdaAccessor( array => { result = new byte[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = array[i]; } })); return(result); }
public override bool Equals(Object o) { if (o is GuardedByteArray) { GuardedByteArray other = (GuardedByteArray)o; //not the true contract of equals. however, //due to the high mathematical improbability of //two unequal strings having the same secure hash, //this approach feels good. the alternative, //decrypting for comparison, is simply too //performance intensive to be used for equals return(_base64SHA1Hash.Equals(other._base64SHA1Hash)); } return(false); }