public static void TestKeyAgreeOriginatorIdentifierOrKey_RoundTrip() { KeyAgreeRecipientInfo recipient = EncodeKeyAgreel(); SubjectIdentifierOrKey originator = recipient.OriginatorIdentifierOrKey; Assert.Equal(SubjectIdentifierOrKeyType.PublicKeyInfo, originator.Type); object value = originator.Value; Assert.True(value is PublicKeyInfo); PublicKeyInfo pki = (PublicKeyInfo)value; AlgorithmIdentifier a = pki.Algorithm; Assert.Equal(Oids.Dh, a.Oid.Value); byte[] key = pki.KeyValue; Assert.NotNull(key); // Key is randomly generated (and encoding makes the length unpredictable) so not much we can do here. Assert.NotEmpty(key); }
public static void TestKeyAgreeOriginatorIdentifierOrKey_FixedValue() { KeyAgreeRecipientInfo recipient = FixedValueKeyAgree1(); SubjectIdentifierOrKey originator = recipient.OriginatorIdentifierOrKey; Assert.Equal(SubjectIdentifierOrKeyType.PublicKeyInfo, originator.Type); object value = originator.Value; Assert.True(value is PublicKeyInfo); PublicKeyInfo pki = (PublicKeyInfo)value; AlgorithmIdentifier a = pki.Algorithm; Assert.Equal(Oids.Dh, a.Oid.Value); byte[] key = pki.KeyValue; byte[] expectedKey = ("0281806F96EF8C53A6919CC976E88B8F426696E7B7970ABC6BD4ABBDCF4CF34F89CEB6E8EF675000FAD2ECA3CAF9D0E51B00" + "4FD19A943F1779748F343FE2059E6E8208D64CB2A5BF33B2C41C20F4AE950D8F8BD720F5747D7930AF86C612088747B5315A" + "E68159A5AE8A80E928AA71F4E889CB2D581845EDC8F79DA5894CB7A40F9FBE").HexToByteArray(); Assert.Equal(expectedKey, key); }
private void Reset(uint originatorChoice, uint version, CAPI.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO encryptedKeyInfo, uint subIndex) { this.m_encryptedKeyInfo = encryptedKeyInfo; this.m_originatorChoice = originatorChoice; this.m_version = (int)version; this.m_originatorIdentifier = (SubjectIdentifierOrKey)null; this.m_userKeyMaterial = new byte[0]; this.m_encryptionAlgorithm = (AlgorithmIdentifier)null; this.m_recipientIdentifier = (SubjectIdentifier)null; this.m_encryptedKey = new byte[0]; this.m_date = DateTime.MinValue; this.m_otherKeyAttribute = (CryptographicAttributeObject)null; this.m_subIndex = subIndex; }