public SymAlgorithms[] FindPreferedAlgorithms() { IEnumerator ieCertificates = this.alCertifications.GetEnumerator(); while (ieCertificates.MoveNext()) { if (!(ieCertificates.Current is CertifiedUserID)) { continue; } CertifiedUserID cuiID = (CertifiedUserID)ieCertificates.Current; IEnumerator ieSignatures = cuiID.Certificates.GetEnumerator(); while (ieSignatures.MoveNext()) { if (!(ieSignatures.Current is SignaturePacket)) { continue; } SignaturePacket spCertificate = (SignaturePacket)ieSignatures.Current; // look only at selfsignatures if (spCertificate.KeyID != this.PrimaryKey.KeyID) { continue; } try { SymAlgorithms[] saReturn = spCertificate.FindPreferedSymAlgorithms(); return(saReturn); } catch (Exception) {} } } throw new Exception("none found!"); }
private SymAlgorithms GetSymAlgorithmPreferences(TransportablePublicKey[] tpkKeys) { bool bCAST5 = true; bool bAES256 = true; bool bAES192 = true; bool bAES128 = true; for (int i = 0; i < tpkKeys.Length; i++) { TransportablePublicKey tpkKey = tpkKeys[i]; ulong lKeyID = tpkKey.PrimaryKey.KeyID; IEnumerator ieCerts = tpkKey.Certifications.GetEnumerator(); while (ieCerts.MoveNext()) { if (!(ieCerts.Current is CertifiedUserID)) { continue; } CertifiedUserID cuiID = (CertifiedUserID)ieCerts.Current; IEnumerator ieSigs = cuiID.Certificates.GetEnumerator(); while (ieSigs.MoveNext()) { if (!(ieSigs.Current is SignaturePacket)) { continue; } SignaturePacket spSig = (SignaturePacket)ieSigs.Current; if ((spSig.Version == SignaturePacketVersionNumbers.v4) && (spSig.KeyID == lKeyID)) { try { bool bTmpCAST5 = false; bool bTmpAES256 = false; bool bTmpAES192 = false; bool bTmpAES128 = false; SymAlgorithms[] saThisKey = spSig.FindPreferedSymAlgorithms(); for (int j = 0; j < saThisKey.Length; j++) { if (saThisKey[j] == SymAlgorithms.AES128) { bTmpAES128 = true; } else if (saThisKey[j] == SymAlgorithms.AES192) { bTmpAES192 = true; } else if (saThisKey[j] == SymAlgorithms.AES256) { bTmpAES256 = true; } else if (saThisKey[j] == SymAlgorithms.CAST5) { bTmpCAST5 = true; } } if (!bTmpCAST5) { bCAST5 = false; } if (!bTmpAES256) { bAES256 = false; } if (!bTmpAES192) { bAES192 = false; } if (!bTmpAES128) { bAES128 = false; } } catch (InvalidOperationException) {} } } } } if (bAES256) { return(SymAlgorithms.AES256); } if (bAES192) { return(SymAlgorithms.AES192); } if (bAES128) { return(SymAlgorithms.AES128); } if (bCAST5) { return(SymAlgorithms.CAST5); } return(SymAlgorithms.Triple_DES); }