public static void VerifyDuplicateKey_DistinctHandles() { using (DSAOpenSsl first = new DSAOpenSsl()) using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle()) using (SafeEvpPKeyHandle firstHandle2 = first.DuplicateKeyHandle()) { Assert.NotSame(firstHandle, firstHandle2); } }
public static void VerifyDuplicateKey_InvalidHandle() { using (DSAOpenSsl dsa = new DSAOpenSsl()) { SafeEvpPKeyHandle pkey = dsa.DuplicateKeyHandle(); using (pkey) { } AssertExtensions.Throws <ArgumentException>("pkeyHandle", () => new DSAOpenSsl(pkey)); } }
public static void VerifyDuplicateKey_InvalidHandle() { using (DSAOpenSsl dsa = new DSAOpenSsl()) { SafeEvpPKeyHandle pkey = dsa.DuplicateKeyHandle(); using (pkey) { } Assert.Throws<ArgumentException>(() => new DSAOpenSsl(pkey)); } }
public static void VerifyDuplicateKey_ValidHandle() { byte[] data = ByteUtils.RepeatByte(0x71, 11); using (DSAOpenSsl first = new DSAOpenSsl()) using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle()) { using (DSA second = new DSAOpenSsl(firstHandle)) { byte[] signed = second.SignData(data, HashAlgorithmName.SHA512); Assert.True(first.VerifyData(data, signed, HashAlgorithmName.SHA512)); } } }
public ICertificatePal CopyWithPrivateKey(DSA privateKey) { DSAOpenSsl typedKey = privateKey as DSAOpenSsl; if (typedKey != null) { return(CopyWithPrivateKey((SafeEvpPKeyHandle)typedKey.DuplicateKeyHandle())); } DSAParameters dsaParameters = privateKey.ExportParameters(true); using (PinAndClear.Track(dsaParameters.X)) using (typedKey = new DSAOpenSsl(dsaParameters)) { return(CopyWithPrivateKey((SafeEvpPKeyHandle)typedKey.DuplicateKeyHandle())); } }
public static void VerifyDuplicateKey_RefCounts() { byte[] data = ByteUtils.RepeatByte(0x74, 11); byte[] signature; DSA second; using (DSAOpenSsl first = new DSAOpenSsl()) using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle()) { signature = first.SignData(data, HashAlgorithmName.SHA384); second = new DSAOpenSsl(firstHandle); } // Now show that second still works, despite first and firstHandle being Disposed. using (second) { Assert.True(second.VerifyData(data, signature, HashAlgorithmName.SHA384)); } }