blob: 37769fefe6a76fd87f40a9b63c0cffdd60e263e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package org.bouncycastle.bcpg;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* Basic type for a symmetric encrypted session key packet
*/
public class SymmetricKeyEncSessionPacket
extends ContainedPacket
{
private int version;
private int encAlgorithm;
private S2K s2k;
private byte[] secKeyData;
public SymmetricKeyEncSessionPacket(
BCPGInputStream in)
throws IOException
{
version = in.read();
encAlgorithm = in.read();
s2k = new S2K(in);
this.secKeyData = in.readAll();
}
public SymmetricKeyEncSessionPacket(
int encAlgorithm,
S2K s2k,
byte[] secKeyData)
{
this.version = 4;
this.encAlgorithm = encAlgorithm;
this.s2k = s2k;
this.secKeyData = secKeyData;
}
/**
* @return int
*/
public int getEncAlgorithm()
{
return encAlgorithm;
}
/**
* @return S2K
*/
public S2K getS2K()
{
return s2k;
}
/**
* @return byte[]
*/
public byte[] getSecKeyData()
{
return secKeyData;
}
/**
* @return int
*/
public int getVersion()
{
return version;
}
public void encode(
BCPGOutputStream out)
throws IOException
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
BCPGOutputStream pOut = new BCPGOutputStream(bOut);
pOut.write(version);
pOut.write(encAlgorithm);
pOut.writeObject(s2k);
if (secKeyData != null && secKeyData.length > 0)
{
pOut.write(secKeyData);
}
out.writePacket(SYMMETRIC_KEY_ENC_SESSION, bOut.toByteArray(), true);
}
}
|