本文整理汇总了C#中PublicKeyAlgorithmTag类的典型用法代码示例。如果您正苦于以下问题:C# PublicKeyAlgorithmTag类的具体用法?C# PublicKeyAlgorithmTag怎么用?C# PublicKeyAlgorithmTag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PublicKeyAlgorithmTag类属于命名空间,在下文中一共展示了PublicKeyAlgorithmTag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetKeyCipher
private static IBufferedCipher GetKeyCipher(
PublicKeyAlgorithmTag algorithm)
{
try
{
switch (algorithm)
{
case PublicKeyAlgorithmTag.RsaEncrypt:
case PublicKeyAlgorithmTag.RsaGeneral:
return CipherUtilities.GetCipher("RSA//PKCS1Padding");
case PublicKeyAlgorithmTag.ElGamalEncrypt:
case PublicKeyAlgorithmTag.ElGamalGeneral:
return CipherUtilities.GetCipher("ElGamal/ECB/PKCS1Padding");
default:
throw new PgpException("unknown asymmetric algorithm: " + algorithm);
}
}
catch (PgpException e)
{
throw e;
}
catch (Exception e)
{
throw new PgpException("Exception creating cipher", e);
}
}
示例2: PublicKeyPacket
/// <summary>
/// Construct a version 4 public key packet.
/// </summary>
/// <param name="algorithm">The algorithm.</param>
/// <param name="time">The time.</param>
/// <param name="key">The key.</param>
public PublicKeyPacket(PublicKeyAlgorithmTag algorithm, DateTime time, IBcpgPublicKey key)
{
_version = 4;
_time = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L;
_algorithm = algorithm;
_key = key;
}
示例3: GetAlgorithm
public static string GetAlgorithm(
PublicKeyAlgorithmTag algId)
{
switch (algId)
{
case PublicKeyAlgorithmTag.RsaGeneral:
return "RsaGeneral";
case PublicKeyAlgorithmTag.RsaEncrypt:
return "RsaEncrypt";
case PublicKeyAlgorithmTag.RsaSign:
return "RsaSign";
case PublicKeyAlgorithmTag.ElGamalEncrypt:
return "ElGamalEncrypt";
case PublicKeyAlgorithmTag.Dsa:
return "DSA";
case PublicKeyAlgorithmTag.EC:
return "EC";
case PublicKeyAlgorithmTag.ECDsa:
return "ECDSA";
case PublicKeyAlgorithmTag.ElGamalGeneral:
return "ElGamalGeneral";
case PublicKeyAlgorithmTag.DiffieHellman:
return "DiffieHellman";
}
return "unknown";
}
示例4: PublicKeyPacket
internal PublicKeyPacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
time = ((uint)bcpgIn.ReadByte() << 24) | ((uint)bcpgIn.ReadByte() << 16)
| ((uint)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte();
if (version <= 3)
{
validDays = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
}
algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
switch ((PublicKeyAlgorithmTag) algorithm)
{
case PublicKeyAlgorithmTag.RsaEncrypt:
case PublicKeyAlgorithmTag.RsaGeneral:
case PublicKeyAlgorithmTag.RsaSign:
key = new RsaPublicBcpgKey(bcpgIn);
break;
case PublicKeyAlgorithmTag.Dsa:
key = new DsaPublicBcpgKey(bcpgIn);
break;
case PublicKeyAlgorithmTag.ElGamalEncrypt:
case PublicKeyAlgorithmTag.ElGamalGeneral:
key = new ElGamalPublicBcpgKey(bcpgIn);
break;
default:
throw new IOException("unknown PGP public key algorithm encountered");
}
}
示例5: SignaturePacket
public SignaturePacket(
int version,
int signatureType,
long keyId,
PublicKeyAlgorithmTag keyAlgorithm,
HashAlgorithmTag hashAlgorithm,
ISignatureSubpacket[] hashedData,
ISignatureSubpacket[] unhashedData,
byte[] fingerprint,
MPInteger[] signature)
{
this._version = version;
this._signatureType = signatureType;
this._keyId = keyId;
this._keyAlgorithm = keyAlgorithm;
this._hashAlgorithm = hashAlgorithm;
this._hashedData = hashedData;
this._unhashedData = unhashedData;
this._fingerprint = fingerprint;
this._signature = signature;
if (hashedData != null)
{
SetCreationTime();
}
}
示例6: GetSignatureName
public static string GetSignatureName(
PublicKeyAlgorithmTag keyAlgorithm,
HashAlgorithmTag hashAlgorithm)
{
string encAlg;
switch (keyAlgorithm)
{
case PublicKeyAlgorithmTag.RsaGeneral:
case PublicKeyAlgorithmTag.RsaSign:
encAlg = "RSA";
break;
case PublicKeyAlgorithmTag.Dsa:
encAlg = "DSA";
break;
case PublicKeyAlgorithmTag.ECDH:
encAlg = "ECDH";
break;
case PublicKeyAlgorithmTag.ECDsa:
encAlg = "ECDSA";
break;
case PublicKeyAlgorithmTag.ElGamalEncrypt: // in some malformed cases.
case PublicKeyAlgorithmTag.ElGamalGeneral:
encAlg = "ElGamal";
break;
default:
throw new PgpException("unknown algorithm tag in signature:" + keyAlgorithm);
}
return GetDigestName(hashAlgorithm) + "with" + encAlg;
}
示例7: PublicKeyEncSessionPacket
internal PublicKeyEncSessionPacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
keyId |= (long)bcpgIn.ReadByte() << 56;
keyId |= (long)bcpgIn.ReadByte() << 48;
keyId |= (long)bcpgIn.ReadByte() << 40;
keyId |= (long)bcpgIn.ReadByte() << 32;
keyId |= (long)bcpgIn.ReadByte() << 24;
keyId |= (long)bcpgIn.ReadByte() << 16;
keyId |= (long)bcpgIn.ReadByte() << 8;
keyId |= (uint)bcpgIn.ReadByte();
algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
switch ((PublicKeyAlgorithmTag) algorithm)
{
case PublicKeyAlgorithmTag.RsaEncrypt:
case PublicKeyAlgorithmTag.RsaGeneral:
data = new BigInteger[]{ new MPInteger(bcpgIn).Value };
break;
case PublicKeyAlgorithmTag.ElGamalEncrypt:
case PublicKeyAlgorithmTag.ElGamalGeneral:
data = new BigInteger[]
{
new MPInteger(bcpgIn).Value,
new MPInteger(bcpgIn).Value
};
break;
default:
throw new IOException("unknown PGP public key algorithm encountered");
}
}
示例8: PublicSubkeyPacket
/// <summary>Construct a version 4 public subkey packet.</summary>
public PublicSubkeyPacket(
PublicKeyAlgorithmTag algorithm,
DateTime time,
IBcpgKey key)
: base(algorithm, time, key)
{
}
示例9: PgpKeyPair
public PgpKeyPair(
PublicKeyAlgorithmTag algorithm,
AsymmetricCipherKeyPair keyPair,
DateTime time)
: this(algorithm, keyPair.Public, keyPair.Private, time)
{
}
示例10: PgpSignatureGenerator
/// <summary>Create a generator for the passed in keyAlgorithm and hashAlgorithm codes.</summary>
public PgpSignatureGenerator(PublicKeyAlgorithmTag keyAlgorithm, HashAlgorithmTag hashAlgorithm)
{
_keyAlgorithm = keyAlgorithm;
_hashAlgorithm = hashAlgorithm;
_dig = DigestUtilities.GetDigest(PgpUtilities.GetDigestName(hashAlgorithm));
_sig = SignerUtilities.GetSigner(PgpUtilities.GetSignatureName(keyAlgorithm, hashAlgorithm));
}
示例11: PublicKeyEncSessionPacket
public PublicKeyEncSessionPacket(long keyId, PublicKeyAlgorithmTag algorithm, BigInteger[] data, byte[] extraData)
{
_version = 3;
_keyId = keyId;
_algorithm = algorithm;
_data = (IBigInteger[])data.Clone();
_extraData = extraData != null ? (byte[])extraData.Clone() : null;
}
示例12: RevocationKey
public RevocationKey(
bool isCritical,
RevocationKeyTag signatureClass,
PublicKeyAlgorithmTag keyAlgorithm,
byte[] fingerprint)
: base(SignatureSubpacketTag.RevocationKey, isCritical, false,
CreateData(signatureClass, keyAlgorithm, fingerprint))
{
}
示例13: PgpPublicKey
/// <summary>
/// Create a PgpPublicKey from the passed in lightweight one.
/// </summary>
/// <remarks>
/// Note: the time passed in affects the value of the key's keyId, so you probably only want
/// to do this once for a lightweight key, or make sure you keep track of the time you used.
/// </remarks>
/// <param name="algorithm">Asymmetric algorithm type representing the public key.</param>
/// <param name="pubKey">Actual public key to associate.</param>
/// <param name="time">Date of creation.</param>
/// <exception cref="ArgumentException">If <c>pubKey</c> is not public.</exception>
/// <exception cref="PgpException">On key creation problem.</exception>
public PgpPublicKey(PublicKeyAlgorithmTag algorithm, IAsymmetricKeyParameter pubKey, DateTime time)
{
if (pubKey.IsPrivate)
throw new ArgumentException(@"Expected a public key", "pubKey");
IBcpgPublicKey bcpgKey;
if (pubKey is RsaKeyParameters)
{
var rK = (RsaKeyParameters)pubKey;
bcpgKey = new RsaPublicBcpgKey(rK.Modulus, rK.Exponent);
}
else if (pubKey is DsaPublicKeyParameters)
{
var dK = (DsaPublicKeyParameters)pubKey;
var dP = dK.Parameters;
bcpgKey = new DsaPublicBcpgKey(dP.P, dP.Q, dP.G, dK.Y);
}
else if (pubKey is ElGamalPublicKeyParameters)
{
var eK = (ElGamalPublicKeyParameters)pubKey;
var eS = eK.Parameters;
bcpgKey = new ElGamalPublicBcpgKey(eS.P, eS.G, eK.Y);
}
else if (pubKey is ECDHPublicKeyParameters)
{
var ecdh = (ECDHPublicKeyParameters)pubKey;
bcpgKey = new ECDHPublicBcpgKey(ecdh.Q, ecdh.PublicKeyParamSet, ecdh.HashAlgorithm, ecdh.SymmetricKeyAlgorithm);
}
else if (pubKey is ECPublicKeyParameters)
{
var ecdsa = (ECPublicKeyParameters)pubKey;
bcpgKey = new ECDSAPublicBcpgKey(ecdsa.Q, ecdsa.PublicKeyParamSet);
}
else
{
throw new PgpException("unknown key class");
}
_publicPk = new PublicKeyPacket(algorithm, time, bcpgKey);
_ids = Platform.CreateArrayList();
_idSigs = Platform.CreateArrayList<IList<IPgpSignature>>();
try
{
Init();
}
catch (IOException e)
{
throw new PgpException("exception calculating keyId", e);
}
}
示例14: PublicKeyPacket
/// <summary>Construct a version 4 public key packet.</summary>
public PublicKeyPacket(
PublicKeyAlgorithmTag algorithm,
DateTime time,
IBcpgKey key)
{
this.version = 4;
this.time = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L;
this.algorithm = algorithm;
this.key = key;
}
示例15: PgpV3SignatureGenerator
/// <summary>Create a generator for the passed in keyAlgorithm and hashAlgorithm codes.</summary>
public PgpV3SignatureGenerator(
PublicKeyAlgorithmTag keyAlgorithm,
HashAlgorithmTag hashAlgorithm)
{
this.keyAlgorithm = keyAlgorithm;
this.hashAlgorithm = hashAlgorithm;
dig = DigestUtilities.GetDigest(PgpUtilities.GetDigestName(hashAlgorithm));
sig = SignerUtilities.GetSigner(PgpUtilities.GetSignatureName(keyAlgorithm, hashAlgorithm));
}