public static DsaSigToMpi ( byte encoding ) : MPInteger[] | ||
encoding | byte | |
Результат | MPInteger[] |
/// <summary>Return a V3 signature object containing the current signature state.</summary> public PgpSignature Generate() { long creationTime = DateTimeUtilities.CurrentUnixMs() / 1000L; byte[] hData = new byte[] { (byte)signatureType, (byte)(creationTime >> 24), (byte)(creationTime >> 16), (byte)(creationTime >> 8), (byte)creationTime }; sig.BlockUpdate(hData, 0, hData.Length); dig.BlockUpdate(hData, 0, hData.Length); byte[] sigBytes = sig.GenerateSignature(); byte[] digest = DigestUtilities.DoFinal(dig); byte[] fingerPrint = new byte[] { digest[0], digest[1] }; // an RSA signature bool isRsa = keyAlgorithm == PublicKeyAlgorithmTag.RsaSign || keyAlgorithm == PublicKeyAlgorithmTag.RsaGeneral; MPInteger[] sigValues = isRsa ? PgpUtilities.RsaSigToMpi(sigBytes) : PgpUtilities.DsaSigToMpi(sigBytes); return(new PgpSignature( new SignaturePacket(3, signatureType, privKey.KeyId, keyAlgorithm, hashAlgorithm, creationTime * 1000L, fingerPrint, sigValues))); }
/// <summary>Return a signature object containing the current signature state.</summary> public PgpSignature Generate() { SignatureSubpacket[] hPkts = hashed, unhPkts = unhashed; if (!packetPresent(hashed, SignatureSubpacketTag.CreationTime)) { hPkts = insertSubpacket(hPkts, new SignatureCreationTime(false, DateTime.UtcNow)); } if (!packetPresent(hashed, SignatureSubpacketTag.IssuerKeyId) && !packetPresent(unhashed, SignatureSubpacketTag.IssuerKeyId)) { unhPkts = insertSubpacket(unhPkts, new IssuerKeyId(false, privKey.KeyId)); } int version = 4; byte[] hData; try { MemoryStream hOut = new MemoryStream(); for (int i = 0; i != hPkts.Length; i++) { hPkts[i].Encode(hOut); } byte[] data = hOut.ToArray(); MemoryStream sOut = new MemoryStream(data.Length + 6); sOut.WriteByte((byte)version); sOut.WriteByte((byte)signatureType); sOut.WriteByte((byte)keyAlgorithm); sOut.WriteByte((byte)hashAlgorithm); sOut.WriteByte((byte)(data.Length >> 8)); sOut.WriteByte((byte)data.Length); sOut.Write(data, 0, data.Length); hData = sOut.ToArray(); } catch (IOException e) { throw new PgpException("exception encoding hashed data.", e); } sig.BlockUpdate(hData, 0, hData.Length); dig.BlockUpdate(hData, 0, hData.Length); hData = new byte[] { (byte)version, 0xff, (byte)(hData.Length >> 24), (byte)(hData.Length >> 16), (byte)(hData.Length >> 8), (byte)hData.Length }; sig.BlockUpdate(hData, 0, hData.Length); dig.BlockUpdate(hData, 0, hData.Length); byte[] sigBytes = sig.GenerateSignature(); byte[] digest = DigestUtilities.DoFinal(dig); byte[] fingerPrint = new byte[] { digest[0], digest[1] }; // an RSA signature bool isRsa = keyAlgorithm == PublicKeyAlgorithmTag.RsaSign || keyAlgorithm == PublicKeyAlgorithmTag.RsaGeneral; MPInteger[] sigValues = isRsa ? PgpUtilities.RsaSigToMpi(sigBytes) : PgpUtilities.DsaSigToMpi(sigBytes); return(new PgpSignature( new SignaturePacket(signatureType, privKey.KeyId, keyAlgorithm, hashAlgorithm, hPkts, unhPkts, fingerPrint, sigValues))); }
public PgpSignature Generate() { long num = DateTimeUtilities.CurrentUnixMs() / 1000; byte[] array = new byte[5] { (byte)signatureType, (byte)(num >> 24), (byte)(num >> 16), (byte)(num >> 8), (byte)num }; sig.BlockUpdate(array, 0, array.Length); dig.BlockUpdate(array, 0, array.Length); byte[] encoding = sig.GenerateSignature(); byte[] array2 = DigestUtilities.DoFinal(dig); byte[] fingerprint = new byte[2] { array2[0], array2[1] }; MPInteger[] signature = ((keyAlgorithm == PublicKeyAlgorithmTag.RsaSign || keyAlgorithm == PublicKeyAlgorithmTag.RsaGeneral) ? PgpUtilities.RsaSigToMpi(encoding) : PgpUtilities.DsaSigToMpi(encoding)); return(new PgpSignature(new SignaturePacket(3, signatureType, privKey.KeyId, keyAlgorithm, hashAlgorithm, num * 1000, fingerprint, signature))); }
/// <summary>Return a signature object containing the current signature state.</summary> public PgpSignature Generate() { MPInteger[] sigValues; int version = 4; MemoryStream sOut = new MemoryStream(); // int index = 0; // // if (!creationTimeFound) // { // hashed[index++] = new SignatureCreationTime(false, DateTime.UtcNow); // } // // if (!issuerKeyIDFound) // { // hashed[index++] = new IssuerKeyId(false, privKey.KeyId); // } SignatureSubpacket[] hPkts, unhPkts; if (!packetPresent(hashed, SignatureSubpacketTag.CreationTime)) { hPkts = insertSubpacket(hashed, new SignatureCreationTime(false, DateTime.UtcNow)); } else { hPkts = hashed; } if (!packetPresent(hashed, SignatureSubpacketTag.IssuerKeyId) && !packetPresent(unhashed, SignatureSubpacketTag.IssuerKeyId)) { unhPkts = insertSubpacket(unhashed, new IssuerKeyId(false, privKey.KeyId)); } else { unhPkts = unhashed; } try { sOut.WriteByte((byte)version); sOut.WriteByte((byte)signatureType); sOut.WriteByte((byte)keyAlgorithm); sOut.WriteByte((byte)hashAlgorithm); MemoryStream hOut = new MemoryStream(); for (int i = 0; i != hPkts.Length; i++) { hPkts[i].Encode(hOut); } byte[] data = hOut.ToArray(); sOut.WriteByte((byte)(data.Length >> 8)); sOut.WriteByte((byte)data.Length); sOut.Write(data, 0, data.Length); } catch (IOException e) { throw new PgpException("exception encoding hashed data.", e); } byte[] hData = sOut.ToArray(); sig.BlockUpdate(hData, 0, hData.Length); dig.BlockUpdate(hData, 0, hData.Length); sOut = new MemoryStream(); sOut.WriteByte((byte)version); sOut.WriteByte((byte)0xff); sOut.WriteByte((byte)(hData.Length >> 24)); sOut.WriteByte((byte)(hData.Length >> 16)); sOut.WriteByte((byte)(hData.Length >> 8)); sOut.WriteByte((byte)(hData.Length)); hData = sOut.ToArray(); sig.BlockUpdate(hData, 0, hData.Length); dig.BlockUpdate(hData, 0, hData.Length); byte[] sigBytes = sig.GenerateSignature(); byte[] digest = DigestUtilities.DoFinal(dig); byte[] fingerPrint = new byte[] { digest[0], digest[1] }; if (keyAlgorithm == PublicKeyAlgorithmTag.RsaSign || keyAlgorithm == PublicKeyAlgorithmTag.RsaGeneral) // an RSA signature { sigValues = new MPInteger[] { new MPInteger(new BigInteger(1, sigBytes)) }; } else { sigValues = PgpUtilities.DsaSigToMpi(sigBytes); } return(new PgpSignature( new SignaturePacket(signatureType, privKey.KeyId, keyAlgorithm, hashAlgorithm, hPkts, unhPkts, fingerPrint, sigValues))); }
public PgpSignature Generate() { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_010c: Expected O, but got Unknown SignatureSubpacket[] array = hashed; SignatureSubpacket[] array2 = unhashed; if (!packetPresent(hashed, SignatureSubpacketTag.CreationTime)) { array = insertSubpacket(array, new SignatureCreationTime(critical: false, global::System.DateTime.get_UtcNow())); } if (!packetPresent(hashed, SignatureSubpacketTag.IssuerKeyId) && !packetPresent(unhashed, SignatureSubpacketTag.IssuerKeyId)) { array2 = insertSubpacket(array2, new IssuerKeyId(critical: false, privKey.KeyId)); } int num = 4; byte[] array4; try { MemoryStream val = new MemoryStream(); for (int i = 0; i != array.Length; i++) { array[i].Encode((Stream)(object)val); } byte[] array3 = val.ToArray(); MemoryStream val2 = new MemoryStream(array3.Length + 6); ((Stream)val2).WriteByte((byte)num); ((Stream)val2).WriteByte((byte)signatureType); ((Stream)val2).WriteByte((byte)keyAlgorithm); ((Stream)val2).WriteByte((byte)hashAlgorithm); ((Stream)val2).WriteByte((byte)(array3.Length >> 8)); ((Stream)val2).WriteByte((byte)array3.Length); ((Stream)val2).Write(array3, 0, array3.Length); array4 = val2.ToArray(); } catch (IOException val3) { IOException exception = val3; throw new PgpException("exception encoding hashed data.", (global::System.Exception)(object) exception); } sig.BlockUpdate(array4, 0, array4.Length); dig.BlockUpdate(array4, 0, array4.Length); array4 = new byte[6] { (byte)num, 255, (byte)(array4.Length >> 24), (byte)(array4.Length >> 16), (byte)(array4.Length >> 8), (byte)array4.Length }; sig.BlockUpdate(array4, 0, array4.Length); dig.BlockUpdate(array4, 0, array4.Length); byte[] encoding = sig.GenerateSignature(); byte[] array5 = DigestUtilities.DoFinal(dig); byte[] fingerprint = new byte[2] { array5[0], array5[1] }; MPInteger[] signature = ((keyAlgorithm == PublicKeyAlgorithmTag.RsaSign || keyAlgorithm == PublicKeyAlgorithmTag.RsaGeneral) ? PgpUtilities.RsaSigToMpi(encoding) : PgpUtilities.DsaSigToMpi(encoding)); return(new PgpSignature(new SignaturePacket(signatureType, privKey.KeyId, keyAlgorithm, hashAlgorithm, array, array2, fingerprint, signature))); }
/// <summary>Return a signature object containing the current signature state.</summary> public PgpSignature Generate() { ISignatureSubpacket[] hPkts = _hashed, unhPkts = _unhashed; if (!PacketPresent(_hashed, SignatureSubpacketTag.CreationTime)) { hPkts = InsertSubpacket(hPkts, new SignatureCreationTime(false, DateTime.UtcNow)); } if (!PacketPresent(_hashed, SignatureSubpacketTag.IssuerKeyId) && !PacketPresent(_unhashed, SignatureSubpacketTag.IssuerKeyId)) { unhPkts = InsertSubpacket(unhPkts, new IssuerKeyId(false, _privKey.KeyId)); } const int version = 4; byte[] hData; try { using (var hOut = new MemoryStream()) { for (var i = 0; i != hPkts.Length; i++) { hPkts[i].Encode(hOut); } var data = hOut.ToArray(); using (var sOut = new MemoryStream(data.Length + 6)) { sOut.WriteByte(version); sOut.WriteByte((byte)_signatureType); sOut.WriteByte((byte)_keyAlgorithm); sOut.WriteByte((byte)_hashAlgorithm); sOut.WriteByte((byte)(data.Length >> 8)); sOut.WriteByte((byte)data.Length); sOut.Write(data, 0, data.Length); hData = sOut.ToArray(); } } } catch (IOException e) { throw new PgpException("exception encoding hashed data.", e); } _sig.BlockUpdate(hData, 0, hData.Length); _dig.BlockUpdate(hData, 0, hData.Length); hData = new byte[] { version, 0xff, (byte)(hData.Length >> 24), (byte)(hData.Length >> 16), (byte)(hData.Length >> 8), (byte)hData.Length }; _sig.BlockUpdate(hData, 0, hData.Length); _dig.BlockUpdate(hData, 0, hData.Length); var sigBytes = _sig.GenerateSignature(); var digest = DigestUtilities.DoFinal(_dig); var fingerPrint = new[] { digest[0], digest[1] }; // an RSA signature var isRsa = _keyAlgorithm == PublicKeyAlgorithmTag.RsaSign || _keyAlgorithm == PublicKeyAlgorithmTag.RsaGeneral; var sigValues = isRsa ? PgpUtilities.RsaSigToMpi(sigBytes) : PgpUtilities.DsaSigToMpi(sigBytes); return(new PgpSignature(new SignaturePacket(_signatureType, _privKey.KeyId, _keyAlgorithm, _hashAlgorithm, hPkts, unhPkts, fingerPrint, sigValues))); }