EncryptJoinAccept uses AES Decrypt to encrypt a join-accept message - The payload contains JoinNonce/AppNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) | MIC - In LoRaWAN 1.0, the AppKey is used - In LoRaWAN 1.1, the NwkKey is used in reply to a JoinRequest - In LoRaWAN 1.1, t
(key types.AES128Key, payload []byte)
| 29 | // - In LoRaWAN 1.1, the NwkKey is used in reply to a JoinRequest |
| 30 | // - In LoRaWAN 1.1, the JSEncKey is used in reply to a RejoinRequest (type 0,1,2) |
| 31 | func EncryptJoinAccept(key types.AES128Key, payload []byte) ([]byte, error) { |
| 32 | if len(payload) != 16 && len(payload) != 32 { |
| 33 | return nil, errInvalidJoinAcceptMessageSize.WithAttributes("size", len(payload)) |
| 34 | } |
| 35 | cipher, err := aes.NewCipher(key[:]) |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | encrypted := make([]byte, len(payload)) |
| 40 | for i := 0; i < len(encrypted); i += 16 { |
| 41 | cipher.Decrypt(encrypted[i:i+16], payload[i:i+16]) |
| 42 | } |
| 43 | return encrypted, nil |
| 44 | } |
| 45 | |
| 46 | // DecryptJoinAccept uses AES Encrypt to decrypt a join-accept message |
| 47 | // - The returned payload contains JoinNonce/AppNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) | MIC |