DecryptJoinAccept uses AES Encrypt to decrypt a join-accept message - The returned 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 or JSEncKey is used
(key types.AES128Key, encrypted []byte)
| 48 | // - In LoRaWAN 1.0, the AppKey is used |
| 49 | // - In LoRaWAN 1.1, the NwkKey or JSEncKey is used |
| 50 | func DecryptJoinAccept(key types.AES128Key, encrypted []byte) ([]byte, error) { |
| 51 | if len(encrypted) != 16 && len(encrypted) != 32 { |
| 52 | return nil, errInvalidJoinAcceptMessageSize.WithAttributes("size", len(encrypted)) |
| 53 | } |
| 54 | cipher, err := aes.NewCipher(key[:]) |
| 55 | if err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | payload := make([]byte, len(encrypted)) |
| 59 | for i := 0; i < len(encrypted); i += 16 { |
| 60 | cipher.Encrypt(payload[i:i+16], encrypted[i:i+16]) |
| 61 | } |
| 62 | return payload, nil |
| 63 | } |
| 64 | |
| 65 | var errInvalidJoinRequestPayloadSize = errInvalidSize("join_request_payload", "join-request payload", "19") |
| 66 |